How to search and replace text in all php-files in a directory and it's subdirectories

It can be done easily with a good combination of sed and xargs.

find . -name "*.php" | xargs -n 1 echo

will show you the power of xargs.

After that, on a sample file, you can test the regexp, with an inplace change (-i) or a backup change (-i.bak). You can also use an other character to replace '/' if your pattern/replacement already have one.

At the end, it should looks like :

pattern=`cat /path/to/pattern`; replacement=`cat /path/to/replacement`
find . -name "*.php" | xargs -n 1 sed -i -e "s|$pattern|$replacement|g"

Try:

find . -name "*.php" -exec sed -i "s/$(cat /path/to/pattern.txt)/$(cat /path/to/replacement.txt)/g" {} \;

where pattern is the pattern to search for and replacement is the text to replace it with.

The -i option for sed edits the files "in place". If you want to create a backup of the file before you edit it, use -i'.bak'.