Suppose there is a code like this on site.com/usertest:

<td class="play_btn"> <a onclick="playAudioNew('1234567890')"><div class="play_new" id="1234567890"></div></a> <input type="hidden" id="1234567890" value="http://blablabla.mp3,294" /> </td> <td class="info"> <div class="duration fl_r" onmousedown="if (window.audioPlayer) audioPlayer.switchTimeFormat('1234567890', event);">4:54</div> <div class="title_wrap"><b><a href="index.php" onclick="if (checkEvent(event)) return; Audio.selectPerformer(event, 'Example'); return false">Name Audio</a></b> - <span class="title">Name Song</span><span class="user"></span></div> </td> 

The code is repeated Nth number of times with the same structure but different values.

<12 input type = "hidden" id = "1234567890" value = " http: //blablabla.mp3 , 294" />

 <123a href="index.php" onclick="if (checkEvent(event)) return; Audio.selectPerformer(event, 'Example'); return false">**Name Audio**</a>< /b> - < span class="title">**Name Song**< /span>< span class="user">< span>< /div> </td> 

I need to parse the Name Audio values ​​— the Name Song and blablabla.mp3 of the entire page. Their values ​​may be different.

    3 answers 3

    It is possible to try all this in xml. I had a similar goal, and I used a simpleXML object.

    Added .

    Like that:

     $xmlStr='ваш html'; $xml = new SimpleXMLElement($xmlStr); foreach ($xml -> div as $k => $info){ if (isset($info['title_wrap'])) { $audioName = $info -> a; $songName = $info -> span[0]; } 

    Wrote to memory, so that 100% guarantee that trample, I will not give =)

    • I would like to know how it will look like - Dmitry Alekseevich
    • Like this: $ xmlStr = 'your html'; $ xml = new SimpleXMLElement ($ xmlStr); foreach ($ xml -> div as $ k => $ info) {if (isset ($ info ['title_wrap'])) {$ audioName = $ info -> a; $ songName = $ info -> span [0]; } I wrote for memory, so it’s 100% guarantee that I’ll trample, I won’t give =) - Yulia Emelyanova

    There was a similar question about parsing HTML — I’m simple and fast; you can find the details here.

      Either through file_get_contents and through the regular schedule, but Julia advised to do better. If you want to be primitive, as I advised, but you don’t need to, learn the regular schedule and parse through this function, and when you understand XML, use it.