Go Back   WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk
Register Blogs FAQ Social Groups CalendarHelp Desk

Reply
 
LinkBack Thread Tools
Old 05-07-2009, 11:57 PM   #1
Advanced Warrior
War Room Member
 
edpudol1973's Avatar
 
Join Date: Aug 2008
Location: Baguio City , Philippines.
Posts: 676
Thanks: 17
Thanked 32 Times in 26 Posts
Social Networking View Member's Twitter Profile 
Contact Info
Send a message via Yahoo to edpudol1973 Send a message via Skype™ to edpudol1973
Default PHP Regular express problem

Please help I am working for more than 3 hours now this problem but I can't think or find way to correct it...

my regular expression is like this
%<h[^>]+>(.*)</h.>%i

It works perfectly if the string look like this
Code:
<H1><A NAME="SECTION000300000000000000000">2 Simple Patterns</A></H1>
Result : <A NAME="SECTION000300000000000000000">2 Simple Patterns</A></H1>
But if string will look like this
Code:
<H1><A NAME="SECTION000300000000000000000">2 Simple Patterns
</A>
</H1>
Result : None

I guess the problem is the line break or not sure..

Thanks in advance

edpudol1973 is offline   Reply With Quote
Old 05-08-2009, 06:16 AM   #2
HyperActive Warrior
War Room Member
 
Join Date: Dec 2003
Location: Trowbridge, United Kingdom.
Posts: 207
Blog Entries: 1
Thanks: 0
Thanked 8 Times in 8 Posts
Contact Info
Send a message via Skype™ to Spencer Westwood
Default Re: PHP Regular express problem

Yes its the line break.. add a \n\l to the match list and see if that helps..

Spencer Westwood is offline   Reply With Quote
Old 05-09-2009, 04:02 AM   #3
xga
Active Warrior
 
Join Date: Aug 2007
Location: , , .
Posts: 54
Thanks: 0
Thanked 10 Times in 3 Posts
Default Re: PHP Regular express problem

Use the 's' pattern modifier so that the (.*) will also match any newlines in the string. For more details, you can read this: PHP: Possible modifiers in regex patterns - Manual
xga is offline   Reply With Quote
Old 05-10-2009, 11:30 AM   #4
Took The Red Pill
War Room Member
 
xiaophil's Avatar
 
Join Date: Apr 2006
Location: Here and Now
Posts: 374
Thanks: 124
Thanked 106 Times in 64 Posts
Contact Info
Send a message via Skype™ to xiaophil
Default Re: PHP Regular express problem

Hi, maybe you could just strip out all the newlines before applying your regex, as they have no meaning in HTML anyway.

$string = str_replace("\n", "", $string);
$string = str_replace("\r", "", $string);
xiaophil is offline   Reply With Quote
Old 05-12-2009, 01:03 PM   #5
HyperActive Warrior
War Room Member
 
Join Date: Jan 2009
Posts: 134
Thanks: 10
Thanked 30 Times in 8 Posts
Default Re: PHP Regular express problem

I would do something like this:

$string = str_replace(array("\n", "\r"), array("", ""), $string);

and then use the following code:

preg_match("#<h[^>]+>(.*)</h.>#i", $string, $match);
$your_result = $match[1];

Aaron Sustar is offline   Reply With Quote
Reply

  WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk

Tags
express, php, problem, regular

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 03:45 AM.