Re: regular expression help!
| From: | Roman Neuhauser | Date: | Thu, 18 Jan 2007 12:28:53 +0000 |
| Subject: | Re: regular expression help! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-247316@lists.php.net to get a copy of this message | ||
# kalles@operamail.com / 2007-01-18 12:34:36 +0200:
> I need to strip all characters from the following text string exept the
> image path...
>
> "<img width=\"99\" height=\"120\" border=\"0\"
> src=\"../../images/new/thumps/4123141112007590373240.jpg\" />"...and then
> store the path to DB. Image path lengh can vary so I guess that I need to
> extract all characters after scr=\" until next \" or somethig
> similar.
This passes with 5.2:
class ImgSrcTest extends Tence_TestCase
{
private $src, $str, $xml;
function setUp()
{
$this->src = 'fubar.jpg';
$this->str = sprintf(
'<img width="99" height="120" border="0"
src="%s" />',
$this->src
);
$this->xml = new SimpleXmlElement($this->str);
}
function testReturnsAttributeAsSimpleXMLElements()
{
return $this->assertEquals('SimpleXMLElement',
get_class($this->xml['src']));
}
function testCastToStringYieldsTheAttributeValue()
{
return $this->assertEquals($this->src, strval($this->xml['src']));
}
}
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991