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
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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.