Jump to content

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.

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.