Kavya Shree Kavya Shree -4 years ago 128
PHP Question

Find and replace text in all files using PHP

Hi Everyone,

I have list of PHP files in my project.If I want to replace

text to
and save it. It will change in all my PHP file in the directory How can I code this.

I can find and replace in single file but I don't know the way to search in whole directory and replace Kindly help me to know the way. Im new to this section.Thanks in advance.

Answer Source

You can use glob to get all files in a directory, glob(__DIR__.'/*.php') will give you all php files in current directory. But if you need to do this in a production server only use it if you can run it as a command line function since the web server not should have write access to the files

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download