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

  • SEARCH
  • Home
  • 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 7819303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:53:31+00:00 2026-06-02T06:53:31+00:00

I have a file import.php in which html data is written under table tags.

  • 0

I have a file “import.php” in which html data is written under table tags. Now i want to parse that data and save that data in an excel sheet. Format is undermentioned and first tr contains the heading and then the data

<html>
  <body>
  <table>
  <tr>
  <th>Name</th>
  <th>Email</th>
  <th>Addr</th>
  <th>City</th>
  </tr>

  <tr>
  <td>Jack</td>
  <td>a@b.com</td>
  <td>xyz Road</td>
  <td>LOS ANGELES</td>
  </tr>

  <tr>
  <td>Sam</td>
  <td>sam@b.com</td>
  <td>pr Road</td>
  <td>TUSTIN</td>
  </tr>
    </table>
  </body>
  </html>
  • 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-02T06:53:33+00:00Added an answer on June 2, 2026 at 6:53 am

    Maybe you’ve better look at this: http://phpexcel.codeplex.com/

    and this: http://www.easyxls.com/

    Another trick is to save your data as a CSV file: http://www.homeandlearn.co.uk/php/php10p6.html

    UPDATE:

    There is no simpler way for saving data into an Excel file directly but saving as CSV. Try this code:

    <?php 
    $data = array( array("firstname" => "Mary", "lastname" => "Johnson", "age" => 25), 
        array("firstname" => "Amanda", "lastname" => "Miller", "age" => 18), 
        array("firstname" => "James", "lastname" => "Brown", "age" => 31), 
        array("firstname" => "Patricia", "lastname" => "Williams", "age" => 7), 
        array("firstname" => "Michael", "lastname" => "Davis", "age" => 43), 
        array("firstname" => "Sarah", "lastname" => "Miller", "age" => 24), 
        array("firstname" => "Patrick", "lastname" => "Miller", "age" => 27) ); 
    
        # filename for download 
        $filename = "website_data_" . date('Ymd') . ".xls"; 
        header("Content-Disposition: attachment; filename=\"$filename\""); 
        header("Content-Type: application/vnd.ms-excel");
        $flag = false; 
        foreach($data as $row) 
        { 
            if(!$flag) 
            { # display field/column names as first row echo 
                implode("\t", array_keys($row)) . "\r\n"; $flag = true; 
            } 
            array_walk($row, 'cleanData');
            print implode("\t", array_values($row)) . "\r\n"; 
        }
    
    
        function cleanData(&$str) 
        { 
            $str = preg_replace("/\t/", "\\t", $str); 
            $str = preg_replace("/\r?\n/", "\\n", $str); 
            if(strstr($str, '"')) 
                $str = '"' . str_replace('"', '""', $str) . '"';
        }
    ?>
    

    As for the seperation of the values from the html tags, you could read your html code from import.php, remove all unnecessary tags, put a seperator to the end of each or tag and then put your values into a single dimension array:

    <?php 
    $htmldata = "";
    $htmldata .= "<html>";
    $htmldata .= "<body>";
    $htmldata .= "<tr>";
    $htmldata .= "<th>header1</th>";
    $htmldata .= "<th>header2</th>";
    $htmldata .= "<th>header3</th>";
    $htmldata .= "<th>header4</th>";
    $htmldata .= "</tr>";
    $htmldata .= "<tr>";
    $htmldata .= "<td>data1</td>";
    $htmldata .= "<td>data2</td>";
    $htmldata .= "<td>data3</td>";
    $htmldata .= "<td>data4</td>";
    $htmldata .= "</tr>";
    $htmldata .= "</body>";
    $htmldata .= "</html>";
    
    //Remove the unecessary tags like <html>, </html>, <body>, </body>, <th>, </th>, <td>, </td>
    $searchfor = array("<html>", "</html>", "<body>", "</body>", "<tr>", "</tr>", "<th>", "</th>", "<td>", "</td>");
    $replacewith = array("", "", "", "", "", "", "", "**SEPERATOR**", "", "**SEPERATOR**"); // Replace </th> & </td> with **SEPERATOR** text
    $htmldata = str_replace($searchfor, $replacewith, $htmldata);
    
    $values = explode("**SEPERATOR**", $htmldata); ;
    print_r($values);
    
    ?>
    

    The first 4 values of the array $values contain your header values. Hope that it helps…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL file which I want to import via PHP 5. In
Ok. I have my query written finally for my php file (which will write
I have an Excel file that I need to import into a (new) Oracle
I have a job to import excel file and save the data to database
I have a python file that will not correctly perform an import. If I
I have an UTF-8 encoded txt file and I want to import it to
I have simple SSIS package where I import data from flat file into SQL
I have a CSV file which contains data seperated with tabs. I need to
I want to create a utility in PHP like phpMyAdmin's import option, which should
I am using PHP to import a CSV file, which originates from an excel

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.