[PHP] help with preg_match

2012-06-03 Thread Chris Purves

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:


Something, something end

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.



--
Chris Purves

"There's a time to think, and a time to act. And this, gentlemen, is no 
time to think." - Sheriff Bud B. Boomer


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] help with preg_match

2012-06-04 Thread Chris Purves
On 2012-06-03 22:37, Robert Williams wrote:
> On Jun 3, 2012, at 17:28, "Chris Purves"  wrote:
> 
>> 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 '>'.
> 
> You need to match something at the beginning. Try this:
> 
> preg_match('/>([^>]*end)/', $curl_response, $matches);
> 
> Assuming a match, you can then look to $matches[1] for your content.
> 

That did it.  In my case, I know that the first letter is capitalized, so I 
used:

preg_match('/[A-Z][^>]*end/', $curl_response, $matches);

Thanks for your help.


-- 
Chris Purves

"The eyes are the groin of the head." Dwight Schrute

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php