Page 1 of 1
Need help with preg_replace
Posted: Thu Mar 23, 2006 6:02 am
by fastfingertips
I have following code:
Code: Select all
$arrPatterns['element'] = '/<<:(.+?):>>/se';
$strContent = preg_replace($arrPatterns['element'], "process_element('$1','".$arrPageDetails."')", $strContent);
But instead to give an array to process_element, $arrPageDetails is coming as a string with value array. Removing slashes causes other problems.
What do i have to do to make $arrPageDetails to be viewed as array?
Posted: Thu Mar 23, 2006 8:45 am
by walkekev
I dont get what you want to do overall. But to make that an array do this
Code: Select all
<?php
$arrPatterns = array("/","<","<",":","(",".","+","?",")",":",">",">","/","s",",e");
?>
That will make each Charecter a diffrent element in the array. each element should be covered by "elemtnt" seperated by a comma
Posted: Thu Mar 23, 2006 9:17 am
by pickle
It looks like you're trying to replace <<:(anything here):>> .
str_replace might be a better option for you as it runs quicker - no need to run the regular expression engine.
If that won't work, try taking the call to process_element() out of quotes. It won't get run if it's in quotes. To be honest, I've never seen this done before, but I guess theoretically it should work.
Posted: Thu Mar 23, 2006 9:19 am
by fastfingertips
I solved, i added an /
Code: Select all
$strContent = preg_replace($arrPatterns['element'], "process_element('$1',\$arrPageDetails)", $strContent);
Posted: Thu Mar 23, 2006 9:23 am
by pickle
Hmm, kind of makes my advice seem pointless eh?
