Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8010971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:53:42+00:00 2026-06-04T18:53:42+00:00

i have this HTML code from my company site. Since I do not have

  • 0

i have this HTML code from my company site. Since I do not have access to the database, I want to parse thru a HTML file and return the values. The code is like this:

<?php
$string = '
<p> <b>HEADER INFO</b>
<table width=100% cellspacing=0>
  <tr align=left>
    <td width=2% colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">&nbsp;&nbsp;</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>View Object:</b> 6600422</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>BPO:</b> G37147359-000000</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Ack Date:</b> 2012-05-28</font></td>
  </tr>
  <tr align=left>
    <td width=2% colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">&nbsp;&nbsp;</font></td>
    <td valign=top colspan=3><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Operation(s):</b> PPS_Queue, PPS_Build, PPS_BoxAll, JPN_End</font></td>
  </tr>
</table>
</p>
<hr>
<p> <b>EXTERNAL ORDER NUMBER REFERENCE</b>
<table width=100% cellspacing=0>
  <tr align=left>
    <td width=2% colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">&nbsp;&nbsp;</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>SAP Sales Order Number</b></font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Customer P.O. Number</b></font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Legacy Order Number</b></font></td>
  </tr>
  <tr align=left>
    <td width=2% colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">&nbsp;&nbsp;</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">0310363858</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">77340892008-120413</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">89FF09378001</font></td>
  </tr>
</table>
</p>
<hr>
<p> <b>PRODUCTS FOR THIS WORK OBJECT/OPERATION(S)</b>
<table width=100% cellspacing=0>
  <tr align=left>
    <td width=2% colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">&nbsp;&nbsp;</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>PL</b></font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Product #</b></font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Qty</b></font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Options</b></font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Serial #</b></font></td>
  </tr>
  <tr align=left>
    <td width=2% colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">&nbsp;&nbsp;</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">3C</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">AP703B</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">1</font></td>
    <td valign=top colspan=1>&nbsp </td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">2S6219000G</font></td>
  </tr>
</table>
</p>
<hr>
<p> <b>Station Info</b>
<table width=100% cellspacing=0>
  <tr align=left>
    <td width=2% colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">&nbsp;&nbsp;</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Start Station:</b> JPN_End</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Location:</b> Done</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Station:</b> </font></td>
  </tr>
  <tr align=left>
    <td width=2% colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">&nbsp;&nbsp;</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Birth Date/Time:</b> 2012-05-23 14:20:32 SGT</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Power Cord:</b></font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Voltage:</b></font></td>
  </tr>
</table>
</p>
<hr>
<p> <b>MATERIAL LIST FOR THIS WORK OBJECT/OPERATION(S)</b>
<table width=100% cellspacing=0>
  <tr align=left>
    <td width=2% colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">&nbsp;&nbsp;</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Part Number</b></font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Qty</b></font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Description</b></font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>BB Type</b></font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Material Location</b></font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\"><b>Serial Number</b></font></td>
  </tr>
  <tr align=left>
    <td width=2% colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">&nbsp;&nbsp;</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">AP703B@@</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">1</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">OEM Generic 1U SAS Enclosure</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">BOM</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">ASSY</font></td>
    <td valign=top colspan=1><font face=\"verdana, arial, helvetica\" size=\"-2\">2S6219000G</font></td>
  </tr>
</table>
</p>
 ';

 $result = parse_data($string);

extract($result);

echo $headertext.'<br />';
echo $sapSON.'<br />';
echo $custPON.'<br />';
echo $legacyON.'<br />';
echo $pl.'<br />';
echo $pn.'<br />';


function parse_data($string){
$string = str_replace('&nbsp;&nbsp;','',$string);

$xml = new DOMDocument();
@$xml->loadHTML($string);

$ret = array();

foreach($xml->getElementsByTagName('p') as $p) {
    $header = trim($p->nodeValue);
}

foreach($xml->getElementsByTagName('td') as $td) {
    $value = trim($td->nodeValue);
    if(!empty($value) && is_numeric($value{0})){
        $ret[] = $value;
    }
}

$ret = array('headertext'=>$header,
             'sapSON'=>$ret[0],
             'custPON'=>$ret[1],
             'legacyON'=>$ret[2],
             'pl'=>$ret[3],
             'pn'=>$ret[4],);

return $ret;
}
?>

Now I want to save the header “External Order Number Reference into i variable which I can call later on.

Also, the second, third and fourth column of the first row correspond to the value of the second, third and fourth column of the second row respectively. I also want to save these values to variables. So basically, I need a PHP script which will parse this HTML file and return me the following:

$header1 = "HEADER INFO";
$viewObject = "6600422";
$BPO = "G37147359-000000";
$AckDate = "2012-05-28";
$Operations = "PPS_Queue, PPS_Build, PPS_BoxAll, JPN_End";
$header2 = "EXTERNAL ORDER NUMBER REFERENCE";
$sapSON = "0310363858";
$custPON = "77340892008-120413";
$legacyON = "89FF09378001";
$header3 = "PRODUCTS FOR THIS WORK OBJECT/OPERATION(S)"
$pl = "3C";
$pn = "AP703B";
$qty = "1";
$options = "&nbsp;";
$serialNo = "2S6219000G";

ETC… Basically, I need all the table contents saved into variables because I will later save them to my database and create a report out of it and generate barcodes for some details

Thanks for the help!

FYI: I do not have access to the database so all I can do is parse thru this HTML file and save the values to variables which I can store to my database later on. Also, do note that the headers are constant, the only changing values are the numbers which are for different orders.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T18:53:43+00:00Added an answer on June 4, 2026 at 6:53 pm

    Here Try this, See it in action

    <?php
    $string = '<p> <b>EXTERNAL ORDER NUMBER REFERENCE</b>
        <table width=100% cellspacing=0>
          <tr align=left>
            <td width=2% colspan=1><font face="verdana, arial, helvetica" size="-2">&nbsp;&nbsp;</font></td>
            <td valign=top colspan=1><font face="verdana, arial, helvetica" size="-2"><b>SAP Sales Order Number</b></font></td>
            <td valign=top colspan=1><font face="verdana, arial, helvetica" size="-2"><b>Customer P.O. Number</b></font></td>
            <td valign=top colspan=1><font face="verdana, arial, helvetica" size="-2"><b>Legacy Order Number</b></font></td>
          </tr>
          <tr align=left>
            <td width=2% colspan=1><font face="verdana, arial, helvetica" size="-2">&nbsp;&nbsp;</font></td>
            <td valign=top colspan=1><font face="verdana, arial, helvetica" size="-2">0310363858</font></td>
            <td valign=top colspan=1><font face="verdana, arial, helvetica" size="-2">77340892008-120413</font></td>
            <td valign=top colspan=1><font face="verdana, arial, helvetica" size="-2">89FF09378001</font></td>
      </tr>
        </table>
    </p>
    ';
    
    $result = parse_data($string);
    
    extract($result);
    
    echo $headertext.'<br />';
    echo $sapSON.'<br />';
    echo $custPON.'<br />';
    echo $legacyON.'<br />';
    
    
    function parse_data($string){
        $string = str_replace('&nbsp;&nbsp;','',$string);
    
        $xml = new DOMDocument();
        @$xml->loadHTML($string);
    
        $ret = array();
    
        foreach($xml->getElementsByTagName('p') as $p) {
            $header = trim($p->nodeValue);
        }
    
        foreach($xml->getElementsByTagName('td') as $td) {
            $value = trim($td->nodeValue);
            if(!empty($value) && is_numeric($value{0})){
                $ret[] = $value;
            }
        }
    
        $ret = array('headertext'=>$header,
                     'sapSON'=>$ret[0],
                     'custPON'=>$ret[1],
                     'legacyON'=>$ret[2]);
    
        return $ret;
    }
    ?>
    

    Edit version 2 (Multiple rows):

    As your table is different for each iteration it becomes quite complex, but I like a challenge. Here you go, hope it helps…

    <?php
    $result = parse_data($string);
    
    //Create Variables From Values
    foreach($result as $key=>$value){
        foreach($value as $key_b=>$value_b){
            $$key_b = $value_b;
        }
    }
    /* --New Available Variables--
        $header0 = HEADER INFO
        $ViewObject = 6600422
        $BPO = G37147359-000000
        $AckDate = 2012-05-28
        $Operations = PPS_Queue, PPS_Build, PPS_BoxAll, JPN_End
        $header1 = EXTERNAL ORDER NUMBER REFERENCE
        $SAPSalesOrderNumber = 0310363858
        $CustomerPONumber = 77340892008-120413
        $LegacyOrderNumber = 89FF09378001
        $header2 = PRODUCTS FOR THIS WORK OBJECT/OPERATION(S)
        $PL = 3C
        $Product = AP703B
        $Qty = 1
        $Options =  
        $Serial = 2S6219000G
        $header3 = Station Info
        $StartStation = JPN_End
        $Location = Done
        $Station = 
        $BirthDateTime = 2012-05-23 14
        $PowerCord = 
        $Voltage = 
        $header4 = MATERIAL LIST FOR THIS WORK OBJECT/OPERATION(S)
        $PartNumber = AP703B@@
        $Description = OEM Generic 1U SAS Enclosure
        $BBType = BOM
        $MaterialLocation = ASSY
        $SerialNumber = 2S6219000G
    */
    
    function parse_data($string){
        $string = str_replace('&nbsp;&nbsp;','',$string);
        $parts = explode('<hr>',$string);
    
        $html = new DOMDocument();
        $ret = array();
        $entry=0;
        foreach($parts as $part){
            @$html->loadHTML($part);
            //Get Header
            foreach($html->getElementsByTagName('p') as $p) {
                $ret[$entry]['header'.$entry] = trim($p->nodeValue);
            }
            $i=0;
            foreach($html->getElementsByTagName('td') as $td){
                $value = trim($td->nodeValue);
                if(empty($value)){
                    continue;
                }
                switch($entry){
                    case 0:
                        $split = explode(':',$value);
                        $ret[$entry][preg_replace('/[^a-zA-Z]/s', '', $split[0])] = trim($split[1]);
                        break;
                    case 1:
                        if(!is_numeric($value{0})){
                            $ret[$entry][$i] = trim($value);
                        }else{
                            $ret[$entry][preg_replace('/[^a-zA-Z]/s', '', $ret[$entry][$i-3])] = trim($value);
                            unset($ret[$entry][$i-3]);
                        }
                        break;
                    case 2:
                        if($i<=4){
                            $ret[$entry][$i] = trim($value);
                        }else{
                            $ret[$entry][preg_replace('/[^a-zA-Z]/s', '', $ret[$entry][$i-5])] = trim($value);
                            unset($ret[$entry][$i-5]);
                        }
                        break;
                    case 3:
                        $split = explode(':',$value);
                        $ret[$entry][preg_replace('/[^a-zA-Z]/s', '', $split[0])] = trim($split[1]);
                        break;
                    case 4:
                        if($i<=5){
                            $ret[$entry][$i] = trim($value);
                        }else{
                            $ret[$entry][preg_replace('/[^a-zA-Z]/s', '', $ret[$entry][$i-6])] = trim($value);
                            unset($ret[$entry][$i-6]);
                        }
                        break;
                }
                $i++;
            }
            $entry++;
        }
        return $ret;
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this XML file I need to extract the HTML Code from mono
From this site: http://www.toymaker.info/Games/html/vertex_shaders.html We have the following code snippet: // transformations provided by
I have this function that takes some user-submitted HTML code from the database: function
I have this code: But it dosn't work. from viewtopic_body.html <!-- BEGIN custom_fields -->
I have downloaded the sample code from this site for FTP Client http://www.lysesoft.com/products/andftp/index.html But
I have several HTML code combinations like this: <h2></h2> <p></p> <iframe></iframe> <hr/> and from
I have this html code that i want to edit with jQuery. Here is
I have this bit of HTML code: <center><table><tr><td>table</td></tr></table></center> How can i unwrap table from
I have this HTML Code: <!doctype html> <html> <head> <meta charset=utf-8> <title>Untitled Document</title> <link
i have this html code: <select name=category id=category> <option value=0>&laquo;Seleziona la categoria&raquo;</option> <option value='1'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.