String splitsen in PHP

Status
Niet open voor verdere reacties.

luc99

Gebruiker
Lid geworden
10 nov 2015
Berichten
98
Welk is de makkelijkste manier om onderstaande string op te splitsen in PHP in aparte delen ?

VRT Radio 1http://cdn-radiotime-logos.tunein.com/s18555q.pngVRT Radio 2 Antwerpenhttp://cdn-profiles.tunein.com/s25705/images/logoq.png?t=159075VRT Studio Brusselhttp://cdn-profiles.tunein.com/s2611/images/logoq.jpgQmusic Limburghttp://cdn-radiotime-logos.tunein.com/s98611q.pngRadio Molhttp://cdn-profiles.tunein.com/s8986/images/logoq.pngNostalgie Extra Nederlandstalighttp://cdn-profiles.tunein.com/s268903/images/logoq.png?t=154272

Met het resultaat dient ik volgende 12 delen te bekomen. Er staan in de string nergens komma's of andere leestekens die gebruikt kunnen worden om te splitsen.
Wel kan wellicht http gebruikt worden als begin punt van een nieuw gedeelte en .png en .jpg om ook een splitsing op te maken.

 
Waar komt die data vandaan? Wel apart dat de spatie mist?
Is het geen XML-output die je zonder XML-format op je scherm ziet, en dat kopieert? Daar doet mij dit aan denken.
 
Laatst bewerkt:
Dat komt van een Bose versterker. Dit is het resultaat als ik de preset opvraag via een Curl commando.
 
Hoe kan ik deze XML dan tonen als dit het geval is.
 
Zal inderdaad XML zijn. Ik vind volgende info terug als voorbeeld.
 

Bijlagen

  • xml.jpg
    xml.jpg
    71,4 KB · Weergaven: 29
Mooi, dan is het inderdaad XML. Kan je de XML-feed ook hier plaatsen?
Aan tekst in plaatjes hebben we weinig. ;)
 
Onderstaande code

Code:
$xml = simplexml_load_string($result);

print_r($xml);

geeft dit resultaat

SimpleXMLElement Object ( [preset] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 1 [createdOn] => 1601238343 [updatedOn] => 1601238343 ) [ContentItem] => SimpleXMLElement Object ( [@attributes] => Array ( [source] => TUNEIN [type] => stationurl [location] => /v1/playback/station/s18555 [sourceAccount] => [isPresetable] => true ) [itemName] => VRT Radio 1 [containerArt] => http://cdn-radiotime-logos.tunein.com/s18555q.png ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 2 [createdOn] => 1601238334 [updatedOn] => 1601238334 ) [ContentItem] => SimpleXMLElement Object ( [@attributes] => Array ( [source] => TUNEIN [type] => stationurl [location] => /v1/playback/station/s25705 [sourceAccount] => [isPresetable] => true ) [itemName] => VRT Radio 2 Antwerpen [containerArt] => http://cdn-profiles.tunein.com/s25705/images/logoq.png?t=159075 ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 3 [createdOn] => 1549097043 [updatedOn] => 1599880176 ) [ContentItem] => SimpleXMLElement Object ( [@attributes] => Array ( [source] => TUNEIN [type] => stationurl [location] => /v1/playback/station/s2611 [sourceAccount] => [isPresetable] => true ) [itemName] => VRT Studio Brussel [containerArt] => http://cdn-profiles.tunein.com/s2611/images/logoq.jpg ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 4 [createdOn] => 1549097015 [updatedOn] => 1603425793 ) [ContentItem] => SimpleXMLElement Object ( [@attributes] => Array ( [source] => TUNEIN [type] => stationurl [location] => /v1/playback/station/s98611 [sourceAccount] => [isPresetable] => true ) [itemName] => Qmusic Limburg [containerArt] => http://cdn-radiotime-logos.tunein.com/s98611q.png ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 5 [createdOn] => 1549096965 [updatedOn] => 1599880233 ) [ContentItem] => SimpleXMLElement Object ( [@attributes] => Array ( [source] => TUNEIN [type] => stationurl [location] => /v1/playback/station/s8986 [sourceAccount] => [isPresetable] => true ) [itemName] => Radio Mol [containerArt] => http://cdn-profiles.tunein.com/s8986/images/logoq.png ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 6 [createdOn] => 1549096935 [updatedOn] => 1549096935 ) [ContentItem] => SimpleXMLElement Object ( [@attributes] => Array ( [source] => TUNEIN [type] => stationurl [location] => /v1/playback/station/s268903 [sourceAccount] => [isPresetable] => true ) [itemName] => Nostalgie Extra Nederlandstalig [containerArt] => http://cdn-profiles.tunein.com/s268903/images/logoq.png?t=154272 ) ) ) )
 
Tipje: zet het eens tussen <pre> en </pre> en het is overzichtelijker in de browser output omdat je ook line-breaks ziet.

PHP:
<?php
echo "<pre>".print_r($xml,true)."</pre>";
?>
 
Ziet er inderdaad al wat beter uit

SimpleXMLElement Object
(
[preset] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 1
[createdOn] => 1601238343
[updatedOn] => 1601238343
)

[ContentItem] => SimpleXMLElement Object
(
[@attributes] => Array
(
[source] => TUNEIN
[type] => stationurl
[location] => /v1/playback/station/s18555
[sourceAccount] =>
[isPresetable] => true
)

[itemName] => VRT Radio 1
[containerArt] => http://cdn-radiotime-logos.tunein.com/s18555q.png
)

)

[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 2
[createdOn] => 1601238334
[updatedOn] => 1601238334
)

[ContentItem] => SimpleXMLElement Object
(
[@attributes] => Array
(
[source] => TUNEIN
[type] => stationurl
[location] => /v1/playback/station/s25705
[sourceAccount] =>
[isPresetable] => true
)

[itemName] => VRT Radio 2 Antwerpen
[containerArt] => http://cdn-profiles.tunein.com/s25705/images/logoq.png?t=159075
)

)

[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 3
[createdOn] => 1549097043
[updatedOn] => 1599880176
)

[ContentItem] => SimpleXMLElement Object
(
[@attributes] => Array
(
[source] => TUNEIN
[type] => stationurl
[location] => /v1/playback/station/s2611
[sourceAccount] =>
[isPresetable] => true
)

[itemName] => VRT Studio Brussel
[containerArt] => http://cdn-profiles.tunein.com/s2611/images/logoq.jpg
)

)

[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 4
[createdOn] => 1549097015
[updatedOn] => 1603425793
)

[ContentItem] => SimpleXMLElement Object
(
[@attributes] => Array
(
[source] => TUNEIN
[type] => stationurl
[location] => /v1/playback/station/s98611
[sourceAccount] =>
[isPresetable] => true
)

[itemName] => Qmusic Limburg
[containerArt] => http://cdn-radiotime-logos.tunein.com/s98611q.png
)

)

[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 5
[createdOn] => 1549096965
[updatedOn] => 1599880233
)

[ContentItem] => SimpleXMLElement Object
(
[@attributes] => Array
(
[source] => TUNEIN
[type] => stationurl
[location] => /v1/playback/station/s8986
[sourceAccount] =>
[isPresetable] => true
)

[itemName] => Radio Mol
[containerArt] => http://cdn-profiles.tunein.com/s8986/images/logoq.png
)

)

[5] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 6
[createdOn] => 1549096935
[updatedOn] => 1549096935
)

[ContentItem] => SimpleXMLElement Object
(
[@attributes] => Array
(
[source] => TUNEIN
[type] => stationurl
[location] => /v1/playback/station/s268903
[sourceAccount] =>
[isPresetable] => true
)

[itemName] => Nostalgie Extra Nederlandstalig
[containerArt] => http://cdn-profiles.tunein.com/s268903/images/logoq.png?t=154272
)

)

)

)
 
Ik moet nu de info hebben van itemName en containerArt
 
Preset is een array, dus je kan $xml['preset'] doorlopen met foreach.
Dan heb je in ContentItem de itemname en containerArt zitten
 
Hopelijk lukt het, laat anders maar weten... :)
 
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan