views:

71

answers:

3
<p>This will serve as a debug page.</p>
<p><img src="http://mattmueller.me/blog/wp-content/uploads/2009/12/threadless.png" alt="Threadless" title="Threadless" width="650" height="150" class="alignnone size-full wp-image-73" /></p>

<p>This will serve as a debug page.</p>
<img src="http://mattmueller.me/blog/wp-content/uploads/2009/12/threadless.png" alt="Threadless" title="Threadless" width="650" height="150" class="alignnone size-full wp-image-73" />

You'll notice that there is no <p> tags surrounding the image tag. I would like this just to remove <p> tags that wrap images. Wordpress is annoying.. essentially. If its easier with a str_replace or something, let me know. But I've tried. And failed so far....

Thanks! Matt Mueller

+2  A: 
s/<p>(<img.*?\/>)<\/p>/$1/g
Anon.
Thanks for the reply! So how would I use this with preg_replace?
Matt
+2  A: 
$x = preg_replace('/<p[^>]*>(<img[^>]*>)<\/p[^>]*>/', '$1', $x);

Where $x is your content

Matt
Your the man! Thanks a lot!
Matt
+3  A: 

Here's a great tool that will help you, hopefully:

http://www.gskinner.com/RegExr/

Moshe
Oh my.. that is the coolest thing ever! Thanks!
Matt
@Matt- you're welcome. I didn't make it, I stumbled across it recently while trying to regex something in TextPad
Moshe