+ Antworten
Ergebnis 1 bis 3 von 3
  1. #1
    Registriert seit
    Sep 2009
    Ort
    Hannover
    Beiträge
    525

    Standard PHP: Parsen bzw. Alternative zu split -> join -> split

    Hallo,
    ich habe nun über eine Registervariable die Antworten der Sonos Geräte empfangen und (ich denke) korrekt zerlegt in einzelne Requests (um diese später weiterzuverarbeiten).

    Der Code dazu ist leider nicht schön und ich denke es geht bestimmt einfacher - ich habe leider keine Idee wie man sowas am Besten macht (das mit dem "split -> implode -> explode" müsste man doch eigentlich wesentlich besser und eleganter lösen können, oder?)?

    PHP-Code:
    <?
    // br_ips: br_sonos_test_regvar (for sonos upnp events)
    // Test / Example script for PHPSonos

    // Include br_ips Libs here for IPSLogger
    require ("functions.inc.php");

    $RegVarID $IPS_INSTANCE;
    $newdata $IPS_VALUE;


    // fetch data in buffer
    $data RegVar_GetBuffer $RegVarID );

    // add received data
    $data .= $newdata;

    echo 
    "!!!!".strpos($data,"NOTIFY / HTTP/1.1")."!!!".strpos($data,"<e:propertyset xmlns")."!!!".strpos($data,"</e:propertyset>");
    // write back data to variable for use in other scripts if not complete
    if((strpos($data,"HTTP/1.1")!==FALSE)&&(strpos($data,"<e:propertyset xmlns")!==FALSE)&&(strpos($data,"</e:propertyset>")!==FALSE))
    {

    $split preg_split('!<\/e:propertyset>!'$data);
    $join implode("</e:propertyset>DummySEP",$split);
    $split explode ("DummySEP"$join);
    $ausgabe $split;



      
    $datei fopen("_subscribe.txt","a+");
      
    fwrite($datei,"\r\n--SOM--------------------------------------------------!\r\n");
    foreach (
    $ausgabe as $item){
    // output only 2 test elems
      
    $datei fopen("_subscribe.txt","a+");
      
    fwrite($datei,"\r\n------------BEG: \r\n"$item ."\r\n--------------!END\r\n");
    }
      
    fwrite($datei,"\r\n--------------------------------------------------EOM--!\r\n");
      
    fclose($datei);




    } else
    {
    RegVar_SetBuffer($RegVarID$data);
    }

    ?>
    Ausgabe (Beispiel):
    Code:
    --SOM--------------------------------------------------!
    
    ------------BEG: 
    NOTIFY / HTTP/1.1
    HOST: 192.168.0.5:6666
    CONTENT-TYPE: text/xml
    CONTENT-LENGTH: 5707
    NT: upnp:event
    NTS: upnp:propchange
    SID: uuid:RINCON_000E5832FB5C01400_sub0000006347
    SEQ: 0
    
    <e:propertyset xmlns:e="urn:schemas-upnp-org:event-1-0"><e:property><LastChange>&lt;Event xmlns=&quot;urn:schemas-upnp-org:metadata-1-0/AVT/&quot; xmlns:r=&quot;urn:schemas-rinconnetworks-com:metadata-1-0/&quot;&gt;&lt;InstanceID val=&quot;0&quot;&gt;&lt;TransportState val=&quot;PLAYING&quot;/&gt;&lt;CurrentPlayMode val=&quot;NORMAL&quot;/&gt;&lt;CurrentCrossfadeMode val=&quot;0&quot;/&gt;&lt;NumberOfTracks val=&quot;3&quot;/&gt;&lt;CurrentTrack val=&quot;2&quot;/&gt;&lt;CurrentSection val=&quot;0&quot;/&gt;&lt;CurrentTrackURI val=&quot;x-rincon-mp3radio://stream.antenne.com/hra-nds/mp3-64/tunein/&quot;/&gt;&lt;CurrentTrackDuration val=&quot;0:00:00&quot;/&gt;&lt;CurrentTrackMetaData val=&quot;&amp;lt;DIDL-Lite xmlns:dc=&amp;quot;http://purl.org/dc/elements/1.1/&amp;quot; xmlns:upnp=&amp;quot;urn:schemas-upnp-org:metadata-1-0/upnp/&amp;quot; xmlns:r=&amp;quot;urn:schemas-rinconnetworks-com:metadata-1-0/&amp;quot; xmlns=&amp;quot;urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/&amp;quot;&amp;gt;&amp;lt;item id=&amp;quot;-1&amp;quot; parentID=&amp;quot;-1&amp;quot; restricted=&amp;quot;true&amp;quot;&amp;gt;&amp;lt;res protocolInfo=&amp;quot;sonos.com-http:*:*:*&amp;quot;&amp;gt;x-sonosapi-stream:s116053?sid=254&amp;amp;amp;flags=32&amp;lt;/res&amp;gt;&amp;lt;r:streamContent&amp;gt;Ville Valo &amp;amp;amp; Natalia Avelon - Summer Wine | Hit-Radio Antenne &amp;lt;/r:streamContent&amp;gt;&amp;lt;r:radioShowMd&amp;gt;&amp;lt;/r:radioShowMd&amp;gt;&amp;lt;upnp:albumArtURI&amp;gt;/getaa?s=1&amp;amp;amp;u=x-sonosapi-stream%3as116053%3fsid%3d254%26flags%3d32&amp;lt;/upnp:albumArtURI&amp;gt;&amp;lt;dc:title&amp;gt;x-sonosapi-stream:s116053?sid=254&amp;amp;amp;flags=32&amp;lt;/dc:title&amp;gt;&amp;lt;upnp:class&amp;gt;object.item&amp;lt;/upnp:class&amp;gt;&amp;lt;/item&amp;gt;&amp;lt;/DIDL-Lite&amp;gt;&quot;/&gt;&lt;r:NextTrackURI val=&quot;aac://hra.hoerradar.de/aac-48_hra-nds#4ro1n49s|0|0|gharva|nnp-48|uen-aqf&quot;/&gt;&lt;r:NextTrackMetaData val=&quot;&amp;lt;DIDL-Lite xmlns:dc=&amp;quot;http://purl.org/dc/elements/1.1/&amp;quot; xmlns:upnp=&amp;quot;urn:schemas-upnp-org:metadata-1-0/upnp/&amp;quot; xmlns:r=&amp;quot;urn:schemas-rinconnetworks-com:metadata-1-0/&amp;quot; xmlns=&amp;quot;urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/&amp;quot;&amp;gt;&amp;lt;item id=&amp;quot;-1&amp;quot; parentID=&amp;quot;-1&amp;quot; restricted=&amp;quot;true&amp;quot;&amp;gt;&amp;lt;res protocolInfo=&amp;quot;aac:*:application/octet-stream:*&amp;quot;&amp;gt;aac://hra.hoerradar.de/aac-48_hra-nds#4ro1n49s|0|0|gharva|nnp-48|uen-aqf&amp;lt;/res&amp;gt;&amp;lt;dc:title&amp;gt;aac-48_hra-nds#4ro1n49s|0|0|gharva|nnp-48|uen-aqf&amp;lt;/dc:title&amp;gt;&amp;lt;upnp:class&amp;gt;object.item&amp;lt;/upnp:class&amp;gt;&amp;lt;/item&amp;gt;&amp;lt;/DIDL-Lite&amp;gt;&quot;/&gt;&lt;r:EnqueuedTransportURI val=&quot;x-sonosapi-stream:s116053?sid=254&amp;amp;flags=32&quot;/&gt;&lt;r:EnqueuedTransportURIMetaData val=&quot;&amp;lt;DIDL-Lite xmlns:dc=&amp;quot;http://purl.org/dc/elements/1.1/&amp;quot; xmlns:upnp=&amp;quot;urn:schemas-upnp-org:metadata-1-0/upnp/&amp;quot; xmlns:r=&amp;quot;urn:schemas-rinconnetworks-com:metadata-1-0/&amp;quot; xmlns=&amp;quot;urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/&amp;quot;&amp;gt;&amp;lt;item id=&amp;quot;-1&amp;quot; parentID=&amp;quot;-1&amp;quot; restricted=&amp;quot;true&amp;quot;&amp;gt;&amp;lt;dc:title&amp;gt;Hit-Radio Antenne&amp;lt;/dc:title&amp;gt;&amp;lt;upnp:class&amp;gt;object.item.audioItem.audioBroadcast&amp;lt;/upnp:class&amp;gt;&amp;lt;desc id=&amp;quot;cdudn&amp;quot; nameSpace=&amp;quot;urn:schemas-rinconnetworks-com:metadata-1-0/&amp;quot;&amp;gt;SA_RINCON65031_&amp;lt;/desc&amp;gt;&amp;lt;/item&amp;gt;&amp;lt;/DIDL-Lite&amp;gt;&quot;/&gt;&lt;PlaybackStorageMedium val=&quot;NETWORK&quot;/&gt;&lt;AVTransportURI val=&quot;x-sonosapi-stream:s116053?sid=254&amp;amp;flags=32&quot;/&gt;&lt;AVTransportURIMetaData val=&quot;&amp;lt;DIDL-Lite xmlns:dc=&amp;quot;http://purl.org/dc/elements/1.1/&amp;quot; xmlns:upnp=&amp;quot;urn:schemas-upnp-org:metadata-1-0/upnp/&amp;quot; xmlns:r=&amp;quot;urn:schemas-rinconnetworks-com:metadata-1-0/&amp;quot; xmlns=&amp;quot;urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/&amp;quot;&amp;gt;&amp;lt;item id=&amp;quot;-1&amp;quot; parentID=&amp;quot;-1&amp;quot; restricted=&amp;quot;true&amp;quot;&amp;gt;&amp;lt;dc:title&amp;gt;Hit-Radio Antenne&amp;lt;/dc:title&amp;gt;&amp;lt;upnp:class&amp;gt;object.item.audioItem.audioBroadcast&amp;lt;/upnp:class&amp;gt;&amp;lt;desc id=&amp;quot;cdudn&amp;quot; nameSpace=&amp;quot;urn:schemas-rinconnetworks-com:metadata-1-0/&amp;quot;&amp;gt;SA_RINCON65031_&amp;lt;/desc&amp;gt;&amp;lt;/item&amp;gt;&amp;lt;/DIDL-Lite&amp;gt;&quot;/&gt;&lt;CurrentTransportActions val=&quot;Play, Stop, Pause, Seek, Next, Previous&quot;/&gt;&lt;TransportStatus val=&quot;OK&quot;/&gt;&lt;r:SleepTimerGeneration val=&quot;0&quot;/&gt;&lt;r:AlarmRunning val=&quot;0&quot;/&gt;&lt;r:SnoozeRunning val=&quot;0&quot;/&gt;&lt;r:RestartPending val=&quot;0&quot;/&gt;&lt;TransportPlaySpeed val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;CurrentMediaDuration val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;RecordStorageMedium val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;PossiblePlaybackStorageMedia val=&quot;NONE, NETWORK&quot;/&gt;&lt;PossibleRecordStorageMedia val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;RecordMediumWriteStatus val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;CurrentRecordQualityMode val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;PossibleRecordQualityModes val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;NextAVTransportURI val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;NextAVTransportURIMetaData val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;/InstanceID&gt;&lt;/Event&gt;</LastChange></e:property></e:propertyset>
    --------------!END
    
    ------------BEG: 
    NOTIFY / HTTP/1.1
    HOST: 192.168.0.5:6666
    CONTENT-TYPE: text/xml
    CONTENT-LENGTH: 5707
    NT: upnp:event
    NTS: upnp:propchange
    SID: uuid:RINCON_000E5832FB5C01400_sub0000006351
    SEQ: 0
    
    <e:propertyset xmlns:e="urn:schemas-upnp-org:event-1-0"><e:property><LastChange>&lt;Event xmlns=&quot;urn:schemas-upnp-org:metadata-1-0/AVT/&quot; xmlns:r=&quot;urn:schemas-rinconnetworks-com:metadata-1-0/&quot;&gt;&lt;InstanceID val=&quot;0&quot;&gt;&lt;TransportState val=&quot;PLAYING&quot;/&gt;&lt;CurrentPlayMode val=&quot;NORMAL&quot;/&gt;&lt;CurrentCrossfadeMode val=&quot;0&quot;/&gt;&lt;NumberOfTracks val=&quot;3&quot;/&gt;&lt;CurrentTrack val=&quot;2&quot;/&gt;&lt;CurrentSection val=&quot;0&quot;/&gt;&lt;CurrentTrackURI val=&quot;x-rincon-mp3radio://stream.antenne.com/hra-nds/mp3-64/tunein/&quot;/&gt;&lt;CurrentTrackDuration val=&quot;0:00:00&quot;/&gt;&lt;CurrentTrackMetaData val=&quot;&amp;lt;DIDL-Lite xmlns:dc=&amp;quot;http://purl.org/dc/elements/1.1/&amp;quot; xmlns:upnp=&amp;quot;urn:schemas-upnp-org:metadata-1-0/upnp/&amp;quot; xmlns:r=&amp;quot;urn:schemas-rinconnetworks-com:metadata-1-0/&amp;quot; xmlns=&amp;quot;urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/&amp;quot;&amp;gt;&amp;lt;item id=&amp;quot;-1&amp;quot; parentID=&amp;quot;-1&amp;quot; restricted=&amp;quot;true&amp;quot;&amp;gt;&amp;lt;res protocolInfo=&amp;quot;sonos.com-http:*:*:*&amp;quot;&amp;gt;x-sonosapi-stream:s116053?sid=254&amp;amp;amp;flags=32&amp;lt;/res&amp;gt;&amp;lt;r:streamContent&amp;gt;Ville Valo &amp;amp;amp; Natalia Avelon - Summer Wine | Hit-Radio Antenne &amp;lt;/r:streamContent&amp;gt;&amp;lt;r:radioShowMd&amp;gt;&amp;lt;/r:radioShowMd&amp;gt;&amp;lt;upnp:albumArtURI&amp;gt;/getaa?s=1&amp;amp;amp;u=x-sonosapi-stream%3as116053%3fsid%3d254%26flags%3d32&amp;lt;/upnp:albumArtURI&amp;gt;&amp;lt;dc:title&amp;gt;x-sonosapi-stream:s116053?sid=254&amp;amp;amp;flags=32&amp;lt;/dc:title&amp;gt;&amp;lt;upnp:class&amp;gt;object.item&amp;lt;/upnp:class&amp;gt;&amp;lt;/item&amp;gt;&amp;lt;/DIDL-Lite&amp;gt;&quot;/&gt;&lt;r:NextTrackURI val=&quot;aac://hra.hoerradar.de/aac-48_hra-nds#4ro1n49s|0|0|gharva|nnp-48|uen-aqf&quot;/&gt;&lt;r:NextTrackMetaData val=&quot;&amp;lt;DIDL-Lite xmlns:dc=&amp;quot;http://purl.org/dc/elements/1.1/&amp;quot; xmlns:upnp=&amp;quot;urn:schemas-upnp-org:metadata-1-0/upnp/&amp;quot; xmlns:r=&amp;quot;urn:schemas-rinconnetworks-com:metadata-1-0/&amp;quot; xmlns=&amp;quot;urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/&amp;quot;&amp;gt;&amp;lt;item id=&amp;quot;-1&amp;quot; parentID=&amp;quot;-1&amp;quot; restricted=&amp;quot;true&amp;quot;&amp;gt;&amp;lt;res protocolInfo=&amp;quot;aac:*:application/octet-stream:*&amp;quot;&amp;gt;aac://hra.hoerradar.de/aac-48_hra-nds#4ro1n49s|0|0|gharva|nnp-48|uen-aqf&amp;lt;/res&amp;gt;&amp;lt;dc:title&amp;gt;aac-48_hra-nds#4ro1n49s|0|0|gharva|nnp-48|uen-aqf&amp;lt;/dc:title&amp;gt;&amp;lt;upnp:class&amp;gt;object.item&amp;lt;/upnp:class&amp;gt;&amp;lt;/item&amp;gt;&amp;lt;/DIDL-Lite&amp;gt;&quot;/&gt;&lt;r:EnqueuedTransportURI val=&quot;x-sonosapi-stream:s116053?sid=254&amp;amp;flags=32&quot;/&gt;&lt;r:EnqueuedTransportURIMetaData val=&quot;&amp;lt;DIDL-Lite xmlns:dc=&amp;quot;http://purl.org/dc/elements/1.1/&amp;quot; xmlns:upnp=&amp;quot;urn:schemas-upnp-org:metadata-1-0/upnp/&amp;quot; xmlns:r=&amp;quot;urn:schemas-rinconnetworks-com:metadata-1-0/&amp;quot; xmlns=&amp;quot;urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/&amp;quot;&amp;gt;&amp;lt;item id=&amp;quot;-1&amp;quot; parentID=&amp;quot;-1&amp;quot; restricted=&amp;quot;true&amp;quot;&amp;gt;&amp;lt;dc:title&amp;gt;Hit-Radio Antenne&amp;lt;/dc:title&amp;gt;&amp;lt;upnp:class&amp;gt;object.item.audioItem.audioBroadcast&amp;lt;/upnp:class&amp;gt;&amp;lt;desc id=&amp;quot;cdudn&amp;quot; nameSpace=&amp;quot;urn:schemas-rinconnetworks-com:metadata-1-0/&amp;quot;&amp;gt;SA_RINCON65031_&amp;lt;/desc&amp;gt;&amp;lt;/item&amp;gt;&amp;lt;/DIDL-Lite&amp;gt;&quot;/&gt;&lt;PlaybackStorageMedium val=&quot;NETWORK&quot;/&gt;&lt;AVTransportURI val=&quot;x-sonosapi-stream:s116053?sid=254&amp;amp;flags=32&quot;/&gt;&lt;AVTransportURIMetaData val=&quot;&amp;lt;DIDL-Lite xmlns:dc=&amp;quot;http://purl.org/dc/elements/1.1/&amp;quot; xmlns:upnp=&amp;quot;urn:schemas-upnp-org:metadata-1-0/upnp/&amp;quot; xmlns:r=&amp;quot;urn:schemas-rinconnetworks-com:metadata-1-0/&amp;quot; xmlns=&amp;quot;urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/&amp;quot;&amp;gt;&amp;lt;item id=&amp;quot;-1&amp;quot; parentID=&amp;quot;-1&amp;quot; restricted=&amp;quot;true&amp;quot;&amp;gt;&amp;lt;dc:title&amp;gt;Hit-Radio Antenne&amp;lt;/dc:title&amp;gt;&amp;lt;upnp:class&amp;gt;object.item.audioItem.audioBroadcast&amp;lt;/upnp:class&amp;gt;&amp;lt;desc id=&amp;quot;cdudn&amp;quot; nameSpace=&amp;quot;urn:schemas-rinconnetworks-com:metadata-1-0/&amp;quot;&amp;gt;SA_RINCON65031_&amp;lt;/desc&amp;gt;&amp;lt;/item&amp;gt;&amp;lt;/DIDL-Lite&amp;gt;&quot;/&gt;&lt;CurrentTransportActions val=&quot;Play, Stop, Pause, Seek, Next, Previous&quot;/&gt;&lt;TransportStatus val=&quot;OK&quot;/&gt;&lt;r:SleepTimerGeneration val=&quot;0&quot;/&gt;&lt;r:AlarmRunning val=&quot;0&quot;/&gt;&lt;r:SnoozeRunning val=&quot;0&quot;/&gt;&lt;r:RestartPending val=&quot;0&quot;/&gt;&lt;TransportPlaySpeed val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;CurrentMediaDuration val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;RecordStorageMedium val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;PossiblePlaybackStorageMedia val=&quot;NONE, NETWORK&quot;/&gt;&lt;PossibleRecordStorageMedia val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;RecordMediumWriteStatus val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;CurrentRecordQualityMode val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;PossibleRecordQualityModes val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;NextAVTransportURI val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;NextAVTransportURIMetaData val=&quot;NOT_IMPLEMENTED&quot;/&gt;&lt;/InstanceID&gt;&lt;/Event&gt;</LastChange></e:property></e:propertyset>
    --------------!END
    Habt ihr vieleicht eine Idee?

    Grüße, Benjamin
    Geändert von bengie (07.11.11 um 23:27 Uhr)
    IP-Symcon V4.x_uLd , div. HM+FS20, Irtrans, EEETop 1611, Linksys WRT, div. Sonos, Iphones + Ipads
    http://www.ip-symcon.de/wiki/Hauptseite
    PHPSonos / br_Sonos: Bitte bei Problemen Datum der Dateien angeben.

  2. #2
    Registriert seit
    Sep 2009
    Ort
    Hannover
    Beiträge
    525

    Das geht doch mit nem Cutter in IPS viel einfacher - müsst Ihr mir dochmal sagen!
    IP-Symcon V4.x_uLd , div. HM+FS20, Irtrans, EEETop 1611, Linksys WRT, div. Sonos, Iphones + Ipads
    http://www.ip-symcon.de/wiki/Hauptseite
    PHPSonos / br_Sonos: Bitte bei Problemen Datum der Dateien angeben.

  3. #3
    Registriert seit
    Feb 2007
    Ort
    Zwickau
    Beiträge
    5,498

    Selber finden macht doch viel mehr Spaß.
    MfG Thomas

    Eaton Xcomfort|FS20|1-Wire|Axis WebCams|Funksystem-868|Gas und Wasserzähler per S0 1-Wire|Amazon Alexa|Daikin Klimaanlage

    Denon+Onkyo Receiver|Visu auf: 10"Touchscr.|Apple iPod Touch|Apple iPhone|Apple iPad|IPS V5.x|Dashboard|WebFront|iFront