I think this would be extremely difficult. Here are some potential approaches and their problems.
Approach 1: Parsing PHP Files
- use
token_get_all()
to parse a PHP source file.
- Look for all of the
T_INLINE_HTML
tokens, which represent the portions of the file that are not PHP code.
- Find and replace text in those portions of the file.
Problem: the only way to reliably find text to replace is by parsing the HTML. But the non-PHP portions of the file are not parsable on their own. They are fragmented and depend on inline PHP code to generate a complete, parse-able file.
Approach 2: Parsing the Output HTML Files
- Save your site's output HTML files from your browser. This will give you complete HTML files to parse.
- Parse those HTML files, saving the text strings that need replacing.
- Go back to the original PHP files, search for those text strings and replace them.
Problem: you are once again faced with the problem of not being able to parse the PHP file. A simple regex approach would work better in this case, because you are searching for exact strings, but it still would not be 100% reliable. And you would not be able to tell what part of the HTML source was from HTML, and what part was generated by PHP.
I think you will be best off doing this by hand. Make yourself a good keyboard macro in your editor, so that once you select text, you can convert it to the PHP function with one keystroke.