-3

I am trying to retrieve value from a html page but I am getting Undefined offset error in PHP. I am trying to get 4th value based upon the date.

HTML Output:
       <table width="438" border="1" bordercolor="#0066FF" cellspacing="0" cellpadding="0" class="gold-table" style=" line-height: 30px;
    text-align: center;">
    <tbody><tr style="font-weight:bold;" align="center">
      <td>Date</td>
      <td> 1 Item</td>
      <td> 2 Item.</td>
      <td> 3 Item.</td>
      <td> 4 Item.</td>
    </tr>
    <tr>
        <td>07/Nov/2018</td>
        <td>10</td>
        <td>20</td>
        <td>30</td>
        <td>40</td>
      </tr>
PHP Code:
$split= explode("$dd", explode("<tbody>", $page)[0])[1];
echo $split;
$dd is todays date 07/November/2018 and $page is my testhtml page

Expected Output 07/Nov/2018 40
  • I don't know who down voted this question. If you are able to answer that's great otherwise its fine. –  Nov 07 '18 at 06:48
  • 1
    it will be helpful if you add what is $dd, $page – Saurabh Gujarani Nov 07 '18 at 07:07
  • can you explain more ? what is $page $dd etc ? – Harish U Warrier Nov 07 '18 at 07:08
  • $dd is todays date 07/November/2018 and page is my testhtml page –  Nov 07 '18 at 07:08
  • 1
    The question as it currently stands is unanswerable. You have not given all the required information (what is in `$dd` or `$page`) and you have not explained what your expected output is. Please edit your question with those details. – Nick Nov 07 '18 at 07:10
  • I have already added the necessary comment. –  Nov 07 '18 at 07:11
  • 1
    What Nick meant, is that you should post your full code and the expected results. If this is your full code, then variable `$dd` is undefined and variable `$page` is undefined. – Eugene Anisiutkin Nov 07 '18 at 07:15
  • 1
    @Josh You should include all information in the question, not only rely on information in the comments. Please take a look at [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and try to follow the guidelines in formulating your question, it will erase a lot of confusion for people who try to understand your problem. – Johan Nov 07 '18 at 07:18
  • 1
    You would be better off looking into DOMDocument to be able to make sense of a HTML page rather than using string manipulation. – Nigel Ren Nov 07 '18 at 07:27
  • _“$dd is todays date 07/November/2018”_ - that value is not even in the HTML you have shown … (`07/Nov/2018` is, but that is something completely different.) Instead of presenting one self-contained, executable example, you show parts of code, with added prose what supposedly contains what, and not even your expected output makes much sense (even if you split the second part at a date value that existed in the code, why would you get “07/Nov/2018 40” with that?) … do you really need more explanation for downvotes? – misorude Nov 07 '18 at 07:43

1 Answers1

0
$dd = '07/Nov/2018';
echo "<pre>";
$rec = (explode("<tbody>", $page));
echo $rec[1];
$split= explode("$dd", explode("<tbody>", $page)[1]);
print_r($split);

Added few debug of code Next steps u need to convert all td tags to array. HTML table to array PHP

Saurabh Gujarani
  • 511
  • 1
  • 7
  • 23
  • Thanks for your comment. I am able to load the above output in a file and then I grep the content from that file. It solves my problem. –  Nov 07 '18 at 07:38