Re:
| From: | Al | Date: | Mon, 04 Jun 2012 12:54:35 +0000 |
| Subject: | Re: | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-318136@lists.php.net to get a copy of this message | ||
On 6/3/2012 8:26 PM, Chris Purves wrote:
Hello, I am trying to use preg_match to match something from an html file. Within the html file is some text that looks like: <span>Something, something end</span> I know that the text ends 'end', but I don't know what the Something, something is. I am using preg_match as follows: preg_match('/[^>]*end/',$curl_response,$matches); I want to match 'end' and everything before it that is not '>'. The problem appears to be with the '>'. I have tried escaping (\>), but it didn't make a difference. The php script hangs when it tries to run this function.You didn't say the phrase is always enclosed in <span> tags; but I assume it is not. This will handle any tags. Try this pattern "%<[^>]+>(.+)\s+end\s*</%i" Note the % instead of "/" because you need it in the pattern. Also, the \s are in case there are extra spaces. Use print_r on your $matches. If you expect more than one, then use preg_match_all()