D
D
digamer2016-04-27 15:17:16
PHP
digamer, 2016-04-27 15:17:16

How to get data from html code using php?

In general, there is such a page code:

<tr>
<td height="20"><a title="Замена кнопки Home" href="/V-iPhone-ne-rabotaet-knopka-Home">Замена кнопки HOME</a></td>
<td align="center"><span id="id169-iphone-5-home">1200</span></td>
<td align="center">от 30 минут</td>
<td align="center">3 месяца</td>
</tr>
<tr>
<td height="20"><a title="Ремонт кнопки блокировки" href="/Ne-rabotaet-knopka-vkliucheniia">Замена кнопки включения</a></td>
<td align="center"><span id="id166-iphone-5-power">1400</span></td>
<td align="center">от 30 минут</td>
<td align="center">3 месяца</td>
</tr>

You need to extract the values ​​of the id attribute from it, and specifically the number itself after id(****).
That is: in this case (169, 166).
I tried to pull the data with regular expressions, but it is very difficult and not clear, a certain amount can be obtained, but what if there are 3 and 5 digits after id?
Also with the help of jquery, but since there you need to get everything from not one page, but from the whole site, I had difficulties. I would like advice on what to do.
As a result, I should get a parser of these id numbers for each page where they are.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OVK2015, 2016-04-27
@digamer

$testStr = '<tr>
<td height="20"><a title="Замена кнопки Home" href="/V-iPhone-ne-rabotaet-knopka-Home">Замена кнопки HOME</a></td>
<td align="center"><span id="id169-iphone-5-home">1200</span></td>
<td align="center">от 30 минут</td>
<td align="center">3 месяца</td>
</tr>
<tr>
<td height="20"><a title="Ремонт кнопки блокировки" href="/Ne-rabotaet-knopka-vkliucheniia">Замена кнопки включения</a></td>
<td align="center"><span id="id166-iphone-5-power">1400</span></td>
<td align="center">от 30 минут</td>
<td align="center">3 месяца</td>
</tr>';
  $regExpWrapper = "#<span(?:.*?)\"id(.*?)\-#si";
  preg_match_all($regExpWrapper, $testStr, $matches);
  print_r($matches);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question