Jump to content

pre_replace()


doddsey_65

Recommended Posts

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/247011-pre_replace/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.