doddsey_65 Posted September 12, 2011 Share Posted September 12, 2011 Im using preg_replace in my template and hook system but have come across a problem. content within a loop is defined in the html as <loop_name-loop_key> so it replaces this with content in the loop which works fine. But adding <loop_name-loop_key> to another custom tag breaks the script. <asf: hook="post_message" params="<loop_name-loop_key>"> doesnt work because the preg_replace has already replaced <loop_name-loop_key> with its php values. I need to replace <loop_name-loop_key> only if it isnt within any other tags like the hook tag. Heres my preg_replaces $content = preg_replace('|\<'.$key.'\-'.$l_key.'\>|i', "<?php echo \$this->tpl_data['$key']['$l_key'][\$i]; ?>", $content); $content = preg_replace('|^\<asf: hook="([a-zA-Z0-9_-]+)" params="\<'.$key.'\-'.$l_key.'\>"\>(.*?)<\/asf: hook\>|sie', "\$this->replace_hook('\\1', '\\3', array(\$this->tpl_data['$key']['$l_key'][$i]));", $content); as you can see since the loop is being replaced before the hook the hook statement becomes invalid. How do i make sure the loop in only replaced if it's not in any other tags? I tried using ^ and $ to define beginning and end but it doesn't work, probably due to the indentation of the html. Quote Link to comment https://forums.phpfreaks.com/topic/247011-pre_replace/ Share on other sites More sharing options...
btherl Posted September 13, 2011 Share Posted September 13, 2011 What if you change the order of those two replacements? As long as you order it so the inside replacements take place after the outside ones you should be ok. Quote Link to comment https://forums.phpfreaks.com/topic/247011-pre_replace/#findComment-1268601 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.