Welcome to WebmasterWorld Guest from 54.167.83.224

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Preg match issue

     
10:12 pm on Apr 11, 2011 (gmt 0)

Full Member

10+ Year Member

joined:Aug 29, 2003
posts:244
votes: 0


Hi guys,

I'm having an issue with preg_match. This is the script I'm running.

preg_match('/\<p align=\"left\"\>\<b\>(.+?)&nbsp/ims',$contents,$cis);
$name = $cis[0];
$name = trim($name);


However, when I echo $name, it also shows the stuff before (<p align="left"><b>) and after (&nbsp) the (.+?). I can use a str_replace to remove this html code but I don't think this is normal behavior for a preg_match. Anyone knows how to solve this issue?

Turbo
5:18 am on Apr 12, 2011 (gmt 0)

Full Member

10+ Year Member

joined:Aug 29, 2003
posts:244
votes: 0


Can someone help me with this one please?
6:34 am on Apr 12, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Place parentheses inside the pattern for what you want to match and the result will be in $cis[1] I think.
10:07 am on Apr 12, 2011 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10542
votes: 8


$cis[0] is supposed to contain the entire matched pattern.
4:10 pm on Apr 12, 2011 (gmt 0)

Full Member

10+ Year Member

joined:Aug 29, 2003
posts:244
votes: 0


Thanks phranque, it works now ;-)
6:51 pm on Apr 12, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


So what did you change?
2:31 pm on Apr 14, 2011 (gmt 0)

Full Member

10+ Year Member

joined:Aug 29, 2003
posts:244
votes: 0


I changed the $cis[0] into $cis[1]. $cis[0] gave me the full match including the parse criteria. $cis[1] just returns the parsed result. Example: I'm looking for the text 'top' in '#*$!topyyy' and I use '#*$!' and 'yyy' as parse criteria. With $cis[0] I got #*$!topyyy as a result. $cis[1] just returned 'top' and that was what I was looking for ;-)
7:59 pm on Apr 14, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Yes, $cis[1] as I thought.
12:56 am on Apr 15, 2011 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10542
votes: 8


Thanks phranque, it works now ;-)

thanks go to g1smd...
=8)
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members