2017-12-11 4 views
0

Ich möchte aus dieser XML-Werte teilen XML - split nur das erste Vorkommen

<SPEC> 
<![CDATA[<ul> 
     <li>Rozmery: 42 x 64 x 36mm</li> 
     <li>Váha: 63g</li> 
     <li>Farba: biela</li> 
     <li>Výkon: 2 x 25w @ 8 ohmov</li> 
     <li>Citlivosť: 98 dB</li> 
     <li>Frekvenčný rozsah: 80Hz-22kHz</li> 
    </ul>]]> 
</SPEC> 

Um zu "Rozmery:" und "42 x 64 x 36mm" ... ohne irgendein HTML-Element. Aber manchmal ist es "Pomer strán: 16: 4" und ich brauche nur noch "Pomer strán:" und "16: 4"

Gibt es eine Möglichkeit, dies zu tun mit PHP-Funktion?

Vielen Dank.

Antwort

0

Ich gehe davon aus, dass du schon irgendwie dein inneres xml bekommst (nicht in OP angegeben). Alles, was Sie brauchen, ist eine einfache RegEx, alles bis zum Doppelpunkt und alles dahinter.

preg_match_all('~(\w+):(.+)~', $yourInnerXML, $matches); 

// $matches[0]: Contains all findings 
// $matches[1]: Contains all findings of the first group (everything before the colon) 
// $matches[2]: Contains all findings of the second group (everyting after the colon) 

könnten Sie spalten auch die innere XML durch Doppelpunkt:

$parts = explode(':', $yourInnerXML); 

// $parts[0]: Contains before colon 
// $parts[1]: Contains after colon 
Verwandte Themen