fapapfap Posted January 22, 2012 Share Posted January 22, 2012 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! Quote Link to comment Share on other sites More sharing options...
fapapfap Posted January 22, 2012 Author Share Posted January 22, 2012 Sorry just to add, there shouldn't be a gap between the main body of code Quote Link to comment Share on other sites More sharing options...
ragax Posted January 22, 2012 Share Posted January 22, 2012 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 Quote Link to comment Share on other sites More sharing options...
fapapfap Posted January 22, 2012 Author Share Posted January 22, 2012 Fantastic! thank you so much! Quote Link to comment Share on other sites More sharing options...
ragax Posted January 22, 2012 Share Posted January 22, 2012 You're very welcome, glad it helped. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.