![]() |
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>But if string will look like this Code: <H1><A NAME="SECTION000300000000000000000">2 Simple PatternsI guess the problem is the line break or not sure.. Thanks in advance |
Re: PHP Regular express problem Yes its the line break.. add a \n\l to the match list and see if that helps.. |
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 |
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); |
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]; |
| All times are GMT -6. The time now is 02:43 PM. |