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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.