small help with regular expressions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

small help with regular expressions

Post by jasongr »

Hi people

Given a PHP string

How can I use eregi to find out if the string contains any tag that is not <p> or </p>

any help with formatting this pattern will be useful
I am new to regular expressions

thanks
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

hmm... untested:

Code: Select all

</?[^p][^>]*>
User avatar
sweatje
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post by sweatje »

Technically

Code: Select all

if ($text != strip_tags($text, '<p>')) { /* must have contained non <p> tags */ }
Should answer the specific question you asked without any regex at all.

Are you really asking a different question?
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Nice way of thinking sweatje... I like that :D
But for you jasongr I suggest to run several tests to see which way is faster.
User avatar
R4000
Forum Contributor
Posts: 168
Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom

Post by R4000 »

if you need a regexp tester, i find http://www.rexv.org/ works brillientyl
Post Reply