Jump to content

preg_replace and wildcard


vroom7

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]
Link to comment
https://forums.phpfreaks.com/topic/4640-preg_replace-and-wildcard/
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);
}[/code]

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.

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.