0

I'm having issues with preg_match_all, my information I used changed and doesn't match the previous code it was using. The table below is only showing 2 row's but it does contain about 30 row's. I need everything in between each in an array.

        <div id="obs-site">
        <table class="data-table" cellpadding=0 cellspacing=0 border=0>
                                    <tr>
                    <td>Apr 27 18:53</td>
                    <td>E 10</td>
                    <td>10</td>
                    <td>Clear</td>
                    <td>CLR</td>
                    <td>77</td>
                    <td>60</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>56%</td>
                    <td>&nbsp;</td>
                    <td>77</td>
                    <td>29.7</td>
                    <td>29.7</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>

                                     <tr>
                    <td>Apr 27 17:53</td>
                    <td>ESE 8</td>
                    <td>10</td>
                    <td>Clear</td>
                    <td>CLR</td>
                    <td>79</td>
                    <td>59</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>50%</td>
                    <td>&nbsp;</td>
                    <td>79</td>
                    <td>29.71</td>
                    <td>29.71</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
        </table>

    </div>

and the code i'm using:

<td>(.*)<\/td>\n<td>(.*)<\/td>\n<td>(.*)<\/td>\n<td>(.*)<\/td>\n<td>(.*)<\/td>\n<td>(.*)<\/td>\n<td>(.*)<\/td>\n<td>(.*)<\/td>\n<td>(.*)<\/td>\n<td>(.*)<\/td>\n<td>(.*)<\/td>\n<td>(.*)<\/td>\n<td>(.*)<\/td>\n<td>(.*)<\/td>\n<td>(.*)<\/td>\n<td>(.*)<\/td>\n<td>(.*)<\/td>\n

the only problem is it's not working. Now if I remove all the tabs/spacers before the td's, its working. What am I doing wrong?

  • You don't use the good tool! Use `DOMDocument` and `DOMXPath` eventually (learn how to use the DOM). Html isn't a simple text file, it is structured data, use this structure. – Casimir et Hippolyte Apr 29 '17 at 00:05
  • 2
    Possible duplicate of [How do you parse and process HTML/XML in PHP?](http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) – Casimir et Hippolyte Apr 29 '17 at 00:06
  • I'm trying to keep the script the same and it uses preg_match_all. This away all my variable's says to same. I"m haven't used DOMDocument and not sure to keep everything the same. – Brandon Holland Apr 29 '17 at 00:20
  • In this case restart your script from zero with a DOM approach. You will learn something new and useful for several languages (since it's implemented in many languages and tools). This way you haven't to write things like: *"the only problem is it's not working"* – Casimir et Hippolyte Apr 29 '17 at 00:36
  • I will try to convert this over to DOM. I'm testing this outside of my main script and its returning 2 blank groups. It is reading all 's but I have 2 lines that as 's, is there away to remove those lines? And is there away I can only use one table (class=data-table) if multiple tables exist ? – Brandon Holland Apr 30 '17 at 00:08
  • Yes, you need to use the class `DOMXPath` (the query method). With it you can request the node list you want with a path in the DOM tree and predicates for each nodes. For example: `//table[@class='data-table']//tr[/td]` (all the tr nodes that have a td node from the table that has the attribute "class" set to "data-table") – Casimir et Hippolyte Apr 30 '17 at 07:13

0 Answers0