[solved] Back reference not working
Posted: Thu Aug 04, 2005 12:18 pm
Hi all,
I'm trying to safely encapsulate any include() statements that may pop up in webpages in my CMS. What I'm trying to do is use preg_replace to find all occurrences of include("/something/here"); and turn it into:
The code I'm using to do this is:
However, with an input string of:
the resulting string is
This is very frustrating as this is the only way I know of, to be able to have an aritrary string with PHP code in it, and have that code executed properly.
Any ideas?
Don't worry folks. Turns out I'm a raging idiot who doesn't know how to use str_replace. Thanks anyway.
I'm trying to safely encapsulate any include() statements that may pop up in webpages in my CMS. What I'm trying to do is use preg_replace to find all occurrences of include("/something/here"); and turn it into:
Code: Select all
<?PHP $func=create_function('','include("/something/here");'); $func(); unset($func); ?>Code: Select all
$content = preg_replace("/(include\(.*?\))/i", "<?PHP \$func=create_function('', 'include($1);'); \$func(); unset(\$func); ?>", $content);Code: Select all
include("something here");
include(should not succeed);
this is a blank line;Code: Select all
;
;
this is a blank line;Any ideas?
Don't worry folks. Turns out I'm a raging idiot who doesn't know how to use str_replace. Thanks anyway.