Jump to content
Updating IPB tonight Read more... ×


This topic is now archived and is closed to further replies.


preg_replace and wildcard

Recommended Posts

I am having some problems getting the right syntax for this. I need to replace any text between [b]<o: [/b]and [b]>[/b]. This is what I am trying, but I know the syntax is wrong:

[code]$text = preg_replace('/\\<o:[^\\]]*\\>/', '', $text);[/code]

Can anyone help me get this right?

Basically I want to strip some html tags that Microsoft Word adds to it's text that look like this: [code]<o:BLAHBLAHBLAH />[/code]

Share this post

Link to post
Share on other sites
[code]$text = htmlspecialchars("<o:BLAHBLAHBLAH />");
if(ereg('&lt;o:(.*) /&gt;', $text)) {
    $text = str_replace("&lt;o:", "", $text);
    $text = str_replace("/&gt;", "", $text);

Maybe, it isn't as elegant as a single line replace, but it does the same thing. Sorry, I thought all you wanted to do was replace what was inside, in which case the solution was simple :o I don't know if you can match on something and replace on another match inside of the match.

Share this post

Link to post
Share on other sites


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.