Forum Moderators: coopster
Does anyone know if a REGEX substitution on PHP source code can be made by PHP before or AFTER it processes the source ?
For example, if the PHP source contains:
<a href="mailto:email@domain.com">email@domain.com</a>
Is there an option in PHP to on-the-fly do a regex substitution to search and replace the above code with something else?
Yes, I know I could just search/replace the actual coded files, but the goal is to not touch the actual source files, just do on-the-fly replacements of certain strings BEFORE or just AFTER PHP processes it.
Does anyone know if this can be done, and if so, how?
Thanks in advance!
if(condition 1) {
$string = '<a href="mailto:email@domain.com">email@domain.com</a>';
} else {
$string = 'something else...';
}
Make sense?
// Get all your output into $output by using $output .= some thing
// Then:
$output = str_replace([whatever you want to do],$output);
echo $output; // $output contains everything between <html> and </html>
[webmasterworld.com...]
mod_substitute [httpd.apache.org] is available in Apache 2.2.7 and later. However, it is also an extension [httpd.apache.org], not base. So unless you have control over your server or a lot of pull with your hosting provider, the Apache mod_substitute method may not be an option for you.
As mentioned, other options include using output buffering to do your own substitution using find/replace or regular expression replacement.