View Full Version : preg_replace Help
J.T.D.
May 9th 2008, 7:42 am
Ok. I'm trying to include files using a tag "{T.filename}". Here's my code:
<?php
$str = '{T.test} test {T.lawl}';
preg_replace("#{T.(.+?)}#is", include(\\1), $str);
?>
I don't know how I would include it successfully. Any help?
- JTD
TeraTask
May 9th 2008, 6:45 pm
Check out "Example #4 Using the 'e' modifier" on the preg_replace php.net page. That's what allows you to execute functions in preg_replace.
J.T.D.
May 10th 2008, 11:17 am
Could you please tell me how? I've been trying:
$str = '{T.tester} hi';
preg_replace("/{T.(.+?)}/e", "file_get_contents(eval('\\1'))", $str);
$str = '{T.tester} hi';
preg_replace("/{T.(.+?)}/e", "'.include('\\1').'", $str);
$str = '{T.tester} hi';
preg_replace("/{T.(.+?)}/e", include("'\\1'")), $str);
And many more variations. I still don't get it =S
hip_hop_x
May 10th 2008, 1:17 pm
preg_match("#{T\.([\S]+)}#i","{T.test} test {T.lawl}", $match);
/*
$match[1] is test
*/
jayshah
May 10th 2008, 1:31 pm
This works on PHP 5:
<?php
function inc($match){
include($match[1]);
}
$str = '{T.test} test {T.lawl}';
echo preg_replace_callback('#{T\.(.+?)}#', inc, $str);
?>
Rep would be appreciated ;)
Jay
J.T.D.
May 10th 2008, 6:19 pm
preg_match("#{T\.([\S]+)}#i","{T.test} test {T.lawl}", $match);
/*
$match[1] is test
*/
That only shows test, and doesn't show more stuff, like lawl...
This works on PHP 5:
<?php
function inc($match){
include($match[1]);
}
$str = '{T.test} test {T.lawl}';
echo preg_replace_callback('#{T\.(.+?)}#', inc, $str);
?>
Rep would be appreciated ;)
Jay
Thanks +Rep. ;)
Thanks everyone!!
- JTD
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.