Re: Re: Regex for extracting quoted strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/03/2011, at 11:08 AM, Shawn McKenzie wrote:

> On 03/05/2011 09:26 AM, Mark Kelly wrote:
>> Hi.
>> 
>> I'm hoping someone can help me extract text between double quotes from a 
>> string.
>> 
>> $regex = 'some magic';
>> $r = preg_match($regex, $sentence, $phrases);
>> 
>> So, if 
>> 
>> $sentence = 'Dave said "This is it". "Nope, that is the wrong colour" she 
>> replied.';
>> 
>> I want $phrases to contain 'This is it' and 'Nope, that is the wrong colour'.
>> 
>> Can anyone help?
>> 
>> Cheers,
>> 
>> Mark
> 
> $regex = '/"([^"]+)"/';
> 
> -- 
> Thanks!
> -Shawn
> http://www.spidean.com

Also, you'll want preg_match_all rather than preg_match.

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


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




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux