DamienRoche Posted October 11, 2008 Share Posted October 11, 2008 I am having trouble understanding this. Here is my code: $html = "blah blah <strong>what.what = huh?</strong> blah blah"; preg_match('#<strong>what.what = huh?</strong>#', $html, $match); echo "<br>match: $match[0]"; The bit inbetween the strong tags will be extracted using a wildcard, so how would I go about escaping special characters? Any insight on this is welcomed. Thanks. Link to comment https://forums.phpfreaks.com/topic/127970-baffled-preg_match-using-wildcard-how-to-escape-possible-special-chars/ Share on other sites More sharing options...
JasonLewis Posted October 11, 2008 Share Posted October 11, 2008 You spelt 'whatever' wrong in the regex. If you want to match any characters inside <strong> tags, try this: <?php $html = "blah blah <strong>whatever</strong> blah blah"; preg_match('#<strong>.*?</strong>#', $html, $match); echo "<br>match: $match[0]"; ?> Oh and $match[1] would be the one you want to echo. Link to comment https://forums.phpfreaks.com/topic/127970-baffled-preg_match-using-wildcard-how-to-escape-possible-special-chars/#findComment-662644 Share on other sites More sharing options...
DamienRoche Posted October 11, 2008 Author Share Posted October 11, 2008 Sorry, I sussed that out. I had a few issues so I've edited the original post to reflect my real problem. I have also tried $match[1]; but that didn't work. Thanks. Link to comment https://forums.phpfreaks.com/topic/127970-baffled-preg_match-using-wildcard-how-to-escape-possible-special-chars/#findComment-662647 Share on other sites More sharing options...
JasonLewis Posted October 11, 2008 Share Posted October 11, 2008 You should be escaping the ?, and perhaps even the full stop (.). Link to comment https://forums.phpfreaks.com/topic/127970-baffled-preg_match-using-wildcard-how-to-escape-possible-special-chars/#findComment-662653 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.