Jump to content

Master regex person's help requested!


fapapfap

Recommended Posts

Within this page source:

 

<tr>

  <td><font size="-1">12.34.56.78</font></td>

  <td><font size="-1">GB</font></td>

 

  <td><font size="-1">random things</font></td>

  <td><font size="-1">randomthings</font></td>

  <td><font size="-1">random things</font></td>

  <td><font size="-1">random things</font></td>

  <td><font size="-1"></font></td>

  <td><font size="-1">30.9500</font></td>

  <td><font size="-1">-2.2000</font></td>

  <td><font size="-1">random things</font></td>

  <td><font size="-1">random things</font></td>

  <td><font size="-1"></font></td>

  <td><font size="-1"></font></td>

 

</tr>

 

I want to save what is in the space of 30.9500, and -2.2000.  It will always be this structure, but random things will be strings of different lengths, and the numbers will change but be in the same floating point format.

 

I cant get it because the tags are all so alike!

 

Link to comment
https://forums.phpfreaks.com/topic/255518-master-regex-persons-help-requested/
Share on other sites

Here you go, fapapfap.

 

Run this code, let me know if it works for you. :)

(There can be more or less space between the lines, it doesn't matter.

 

Code:

<?php
$regex=',(?s)(?><tr>(?:[ \r\n]*)(?:<td.*?</td>(?:[ \r\n]*)){7})<td>[^>]+>([^<]+)(?:[^>]+>){4}([^<]+),';
$string='<tr>
  <td><font size="-1">12.34.56.78</font></td>
  <td><font size="-1">GB</font></td>

  <td><font size="-1">random things</font></td>
  <td><font size="-1">randomthings</font></td>
  <td><font size="-1">random things</font></td>
  <td><font size="-1">random things</font></td>
  <td><font size="-1"></font></td>
  <td><font size="-1">30.9500</font></td>
  <td><font size="-1">-2.2000</font></td>
  <td><font size="-1">random things</font></td>
  <td><font size="-1">random things</font></td>
  <td><font size="-1"></font></td>
  <td><font size="-1"></font></td>

</tr>';

preg_match($regex,$string,$match);
echo $match[1].'<br />';
echo $match[2].'<br />';
?>

 

Output:

30.9500

-2.2000

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.