PREG_REPLACE - Help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Seas.Comander
Forum Newbie
Posts: 2
Joined: Sat Sep 05, 2009 3:31 am

PREG_REPLACE - Help!

Post 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.
Last edited by Seas.Comander on Sat Sep 05, 2009 1:57 pm, edited 2 times in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: preg_replace woes

Post by Benjamin »

This post may be of interest.
Seas.Comander
Forum Newbie
Posts: 2
Joined: Sat Sep 05, 2009 3:31 am

Re: preg_replace woes

Post 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);
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: PREG_REPLACE - Help!

Post by Jonah Bron »

If that is exactly what you are replacing, just use str_replace().
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: PREG_REPLACE - Help!

Post 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.
Post Reply