(Haven't received William's email yet => scavenging Jochem's reply.) # jochem@xxxxxxxxxxxxx / 2007-01-18 18:01:19 +0100: > William Stokes wrote: > > "Roman Neuhauser" <neuhauser@xxxxxxxxxx> kirjoitti > >> 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'])); > >> } > >> } > > > > Could you specify the functionality of your script a bit please. (How it > > works) It's a unit test showing how you can use SimpleXML to do what you want. It's written for Testilence out of sheer laziness, but any unit testing tool would do (after cosmetic changes to the code). The "test case" contains two pretty obvious tests, just read the function names, their bodies should be pretty obvious. On thing that might be a little non-obvious is the strval(): that was the only way I found to get the string out of the very uncommunicative SimpleXMLElement. > > I forgot to mention that this part: > > > > <img width="99" height="120" border="0" src="%s" />', > > > > is not always the same. The image properties can vary. That's one of the reasons I didn't go the regexp route. Don't treat XML as text, it's not. -- 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php