Page 1 of 1

PREG_REPLACE - Help!

Posted: Sat Sep 05, 2009 3:40 am
by Seas.Comander
I need a little help coming up with the right preg_replace for a multilined pattern. This is the pattern I am searching for exactly:

Code: Select all

</center>
</td>
</tr>
</table>
</td>
</tr>
I have what I want to replace it with in the variable: $extra
and the html pages needed edited is stored in: $content

So what I need is something like: $content = preg_replace($pattern,$extra,$content);
Where $pattern is the $pattern I need that will find the multilined code above.

Re: preg_replace woes

Posted: Sat Sep 05, 2009 3:45 am
by Benjamin
This post may be of interest.

Re: preg_replace woes

Posted: Sat Sep 05, 2009 4:13 am
by Seas.Comander
This is the best I can come up with, but none of these seem to work, lol:

$content=preg_replace('|<\/center>.*?<\/td>.*?<\/tr>.*?<\/table>.*?<\/td>.*?<\/tr>|s',$extra,$content);
$content = preg_replace('|</center>(.*$)</td>(.*$)</tr>(.*$)</table>(.*$)</td>(.*$)</tr>/|ms',$extra,$content);

Re: PREG_REPLACE - Help!

Posted: Sat Sep 05, 2009 3:30 pm
by Jonah Bron
If that is exactly what you are replacing, just use str_replace().

Re: PREG_REPLACE - Help!

Posted: Sat Sep 05, 2009 6:36 pm
by Ollie Saunders
Jonah Bron wrote:If that is exactly what you are replacing, just use str_replace().
Judging from the thread author's attempts I think he wants to match more than that.