Link to home
Create AccountLog in
Avatar of OmniUnlimited
OmniUnlimitedFlag for United States of America

asked on

I Need A PHP Regex Expression

Hello Experts,

I was wondering if one of you whizes at regular expressions could come up with one that would help me to eliminate some tags in WordPress.  I've tried to figure out regexes, but only managed to get a headache from it.  I use an exec-PHP plugin to execute php within pages and posts, and so I have placed some image tags within the posts, but I need to strip them out to isolate just the text in the posts.  The problem is that I use php tags within the image tags so the built-in function strip_tags does not work correctly.  The following is an example of one of the tags:

<img src="<?php echo get_cur_theme_uri(); ?>/images/image001.jpg" alt="" />

While it would be great if you could come up with a regex to eliminate this tag altogether, I would appreciate it more if you could come up with an expression that would eliminate all html tags, ignoring any php coding that may be present within the tags.
Avatar of Kalpan
Kalpan
Flag of India image

$strTag = '<img src="<?php echo get_cur_theme_uri(); ?>/images/image001.jpg" alt="" />';
preg_match_all('/(src)=("[^"]*")/i',$strTag, $strTag);
print_r($strTag);
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
If I read the requirement correctly:
Find:

<[^<]*((?:<\?php[^>]+>)?)[^>]*>

Replace:

$1

Open in new window

Avatar of OmniUnlimited

ASKER

Thanks to all who participated in trying to assist me with the problem.  I really, really appreciate the outstanding response I received.  I copied and pasted all your codes into my program, and the only one that worked was Ray's, so Ray gets awarded full points.