Welcome to WebmasterWorld Guest from 50.19.34.234

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Preg match issue

     

turbohost

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

10+ Year Member



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

turbohost

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

10+ Year Member



Can someone help me with this one please?

g1smd

6:34 am on Apr 12, 2011 (gmt 0)

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



Place parentheses inside the pattern for what you want to match and the result will be in $cis[1] I think.

phranque

10:07 am on Apr 12, 2011 (gmt 0)

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



$cis[0] is supposed to contain the entire matched pattern.

turbohost

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

10+ Year Member



Thanks phranque, it works now ;-)

g1smd

6:51 pm on Apr 12, 2011 (gmt 0)

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



So what did you change?

turbohost

2:31 pm on Apr 14, 2011 (gmt 0)

10+ Year Member



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 ;-)

g1smd

7:59 pm on Apr 14, 2011 (gmt 0)

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



Yes, $cis[1] as I thought.

phranque

12:56 am on Apr 15, 2011 (gmt 0)

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



Thanks phranque, it works now ;-)

thanks go to g1smd...
=8)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month