Jump to content

Easy preg_match Problem


Seas.Comander

Recommended Posts

I've been working on this forever now and am tired of not finding the answer so I'm just going to ask here. I need to find the following consecutive 6 lines that appear in many of my .html pages, I'm going to replace those lines with new html...

 

</center>

</td>

</tr>

</table>

</td>

</tr>

 

This is what I've come up with for this right now, but as you probably can see just by looking at it, it doesn't work.

 

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

Link to comment
https://forums.phpfreaks.com/topic/173256-easy-preg_match-problem/
Share on other sites

I'm not actually sure why your pattern doesn't work, but it must have something to do with the 'inline' end-of-line anchors. You should just use \s* (zero or more whitespace characters) instead:

 

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

I also made the search case insensitive.

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.