Jump to content


Photo

preg_replace and wildcard


  • Please log in to reply
2 replies to this topic

#1 vroom7

vroom7
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 10 March 2006 - 10:05 PM

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

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

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:
<o:BLAHBLAHBLAH />


#2 k.soule

k.soule
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIllinois

Posted 11 March 2006 - 02:39 AM

$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.

#3 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 11 March 2006 - 02:35 PM

$text = preg_replace('/<o:.*?\/>/', '', $text);




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users