0

Hi I want print a string xml (title) in php

I have tried that:

<?php
$xml = "<tracks>
<radioname>Radio</radioname>
<track>
<uniqueid>400000</uniqueid>
<title>Mask Off</title>
<artists>Future</artists>
</track>
</tracks>";

$xml = simplexml_load_string($xml); 
echo $xml->tracks->track->title;

?>
Cristoforo
  • 17
  • 3

1 Answers1

0

You should try this:

$xml = '<?xml version="1.0" encoding="UTF-8"?><tracks>
<radioname>Radio</radioname>
<track>
<uniqueid>400000</uniqueid>
<title>Mask Off</title>
<artists>Future</artists>
</track>
</tracks>';

$xmlcont = new SimpleXMLElement($xml);

echo $xmlcont->track->title;

Output will be:

Mask Off
NID
  • 3,238
  • 1
  • 17
  • 28
  • File is on another page?? can you elaborate? if this works ,please mark this as accepted so others would know this works. – NID Jul 05 '17 at 05:14
  • i don't get this file on another page thing?? what exactly are you trying to do?? if you could elaborate your requirement may be i could helpu – NID Jul 05 '17 at 06:20
  • I would like to extract the xml file from here: http://api.radionomy.com/currentsong.cfm?radiouid=80b5e81c-c769-478a-aee7-fbe149aacfe3&apikey=cf415862-c0ac-4085-bc03-be80a26f9063&callmeback=yes&type=xml&cover=yes&previous=yes.xml And then print title from that file – Cristoforo Jul 05 '17 at 06:30
  • you might want to read this https://stackoverflow.com/questions/28538787/php-read-a-php-url-as-xml-and-parse-it – NID Jul 05 '17 at 06:38
  • it can be done.. can you ask this new requirement as a new question.. so i could properly answer there. – NID Jul 05 '17 at 06:45