Regular expressions, filter option1 OR option2
| From: | Camilo Sperberg | Date: | Wed, 18 Aug 2010 18:01:10 +0000 |
| Subject: | Regular expressions, filter option1 OR option2 | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-307537@lists.php.net to get a copy of this message | ||
Hello list :)
Just a short question which I know it should be easy, but I'm no expert yet
in regular expressions.
I've got a nice little XML string, which is something like this but can be
changed:
<?xml version="1.0" encoding="utf-8"?>
<boolean xmlns="http://tempuri.org/">false</boolean>
The boolean value can be true or false, so what I want to do, is filter it.
I've done it this way, but I know it can be improved (just because I love
clean coding and also because I want to master regular expressions xD):
$result = preg_match('/true/',$curl_response);
if ($result == 0) $result = preg_match('/false/',$curl_response);
I've also tried something like:
$result = preg_replace('/^(true)|^(false)/','',$curl_response); // if not
true OR not false => replace with empty
and also '/^true|^false/' which doesn't seem to work.
Any ideas to filter this kind of string in just one expression?
Thanks in advance :)
--
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/