Reputation: 11
How to write php so I know the link here? There will always be different links
<response>
<redirect>
http://www.example.com/
</redirect>
<code>0</code>
<description>OK</description>
</response>
Upvotes: 0
Views: 53
Reputation: 19502
Use DOM+Xpath:
$xml = <<<'XML'
<response>
<redirect>http://www.example.com/</redirect>
<code>0</code>
<description>OK</description>
</response>
XML;
$dom = new DOMDocument();
$dom->loadXml($xml);
$xpath = new DOMXpath($dom);
var_dump($xpath->evaluate('string(/response/redirect)'));
Output:
string(23) "http://www.example.com/"
Upvotes: 0
Reputation: 744
simplexml_load_string
This should answer all your questions...
http://www.php.net/manual/en/function.simplexml-load-string.php
Upvotes: 0
Reputation: 13738
try simplexml
$xml ='<response>
<redirect>
http://www.example.com/
</redirect>
<code>0</code>
<description>OK</description>
</response>';
$xml = simplexml_load_string($xml);
echo $xml->redirect; // http://www.example.com/
Upvotes: 1