Page 1 of 1

[solved] Back reference not working

Posted: Thu Aug 04, 2005 12:18 pm
by pickle
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:

Code: Select all

<?PHP $func=create_function('','include("/something/here");'); $func(); unset($func); ?>
The code I'm using to do this is:

Code: Select all

$content = preg_replace("/(include\(.*?\))/i", "<?PHP \$func=create_function('', 'include($1);'); \$func(); unset(\$func); ?>", $content);
However, with an input string of:

Code: Select all

include("something here");
include(should not succeed);
this is a blank line;
the resulting string is

Code: Select all

;
;
this is a blank line;
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.

Re: [solved] Back reference not working

Posted: Thu Aug 04, 2005 12:52 pm
by patrikG
pickle wrote:
Don't worry folks. Turns out I'm a raging idiot who doesn't know how to use str_replace. Thanks anyway.
I won't quote you on that ;)

Re: [solved] Back reference not working

Posted: Thu Aug 04, 2005 1:05 pm
by pickle
patrikG wrote:I won't quote you on that ;)
And yet you just did :wink:

It was just one of those things that created such rage that I can't use English to describe it.

Re: [solved] Back reference not working

Posted: Thu Aug 04, 2005 1:08 pm
by patrikG
pickle wrote:
patrikG wrote:I won't quote you on that ;)
And yet you just did :wink:
Ack, how shameful of me ;)
pickle wrote:It was just one of those things that created such rage that I can't use English to describe it.
I know the feeling only too well :?