homepage Welcome to WebmasterWorld Guest from 54.196.159.11
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Preg match issue
turbohost




msg:4295794
 10:12 pm on Apr 11, 2011 (gmt 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

 

turbohost




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

Can someone help me with this one please?

g1smd




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

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

phranque




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

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

turbohost




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

Thanks phranque, it works now ;-)

g1smd




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

So what did you change?

turbohost




msg:4297575
 2:31 pm on Apr 14, 2011 (gmt 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 ;-)

g1smd




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

Yes, $cis[1] as I thought.

phranque




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

Thanks phranque, it works now ;-)

thanks go to g1smd...
=8)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved