0

hey i am trying to parse html with php. My php script is the following

    <?php

   $page = file_get_contents('http://localhost/pim/station.php');
   preg_match_all('/<td.*?>(.*?)<\/td>/si', $page, $agent_name);
    echo json_encode($agent_name);
      ?>

And this is the html that i am trying to parse

          <form name="maforme" method="post" action="">
            <center class="p2Text">

             <div id='table'>
               <table id="tablex" width="99%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#111111" style="font-family: Arial; font-size: 10px; border-collapse: collapse; height: 53px" name="table">
               <thead>
                 <tr align="center"  >
                   <th height="30" colspan="7" align="center" valign="middle" bgcolor="#F2FAE7" class="sous_TITRE" >
                     TUNIS                         &nbsp;=====>&nbsp;
                     SIDI AHMED                         </th>
  </tr>
                 <tr align="center">
                   <th width="110" height="24" colspan="1" valign="middle" bgcolor="#F2FAE7" class="titre_tableau">Ligne</th>
  <th width="72" height="24" colspan="1" valign="middle" bgcolor="#F2FAE7" class="titre_tableau">Station d&eacute;part</th>
  <th width="50" height="24" valign="middle" bgcolor="#F2FAE7" class="titre_tableau">Heure d&eacute;part </th>
  <th width="68" height="24" colspan="1" valign="middle" bgcolor="#F2FAE7" class="titre_tableau">Station arriv&eacute;e</th>
  <th width="52" height="24" valign="middle" bgcolor="#F2FAE7" class="titre_tableau">Heure arriv&eacute;e</th>
  <th width="51" height="24" valign="middle" bgcolor="#F2FAE7" class="titre_tableau">Distance</th>
  <th width="47" valign="middle" bgcolor="#F2FAE7" class="titre_tableau">Tarif (DT) </th>
  </tr>
                 </thead>
               <tbody id="offTblBdy">




                 <tr class="tabnormal" onMouseOver="this.className='tabover'" onMouseOut="this.className='tabnormal'">
                   <td height="30" align="left" valign="middle" class="text_normal_colore">TUNIS - TABARKA <span class="unnamed1">(N)</span></td>
                      <td height="30" align="center" valign="middle" class="bluetext" >&nbsp; TUNIS                            <input type="hidden" value="7"> </td>
                      <td height="30" align="center" valign="middle"  >&nbsp; 06:30 </td>
                      <td height="30" align="center" valign="middle" class="bluetext">&nbsp; SIDI AHMED </td>
                      <td height="30" align="center" valign="middle" >&nbsp;07:40 </td>

                            <td height="30" align="center" valign="middle" class="style10">&nbsp;70 </td>
                         <td height="30" align="center" valign="middle" class="text_normal_colore">4.190</td>
                 </tr>

Actually i am trying to parse the value inside the td of the table with the id offTblBdy plz can someone help

  • https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – AbraCadaver May 16 '17 at 21:43
  • 1
    Use a DOM parser library, like `DOMDocument`. – Barmar May 16 '17 at 21:49
  • 1
    Couple of things we don't say here: "plz" and "parse html with regex". The latter is best called extracting. "Parsing" is something different altogether. -- Also is your question really just how the get the `[n]`th array element? / Else elaborate on where your efforts lead and other findings. – mario May 16 '17 at 21:49

0 Answers0