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 7549587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:58:57+00:00 2026-05-30T09:58:57+00:00

I have extracted records from a database and stored them on an HTML page

  • 0

I have extracted records from a database and stored them on an HTML page with only text. Each record is stored in a <p> paragraph field and separated by a line break <br /> and a line <hr>.
For example:

Company Name<br/>
555-555-555<br />
Address Line 1<br />
Address Line 2<br />
Website: www.example.com<br />

I just need to place these records into a CSV file. I used fputcsv in combination with array() and file_get_contents() but it read my the entire source code of the webpage into a .csv file and alot of data was missing as well. These are multiple records stored in the same format. So after an entire record block as seen above, it is separate by an <hr> line tag. I want to read the company name into the Name column, the Phone number into the Phone column, the addresses into the Address column and the Website into the Website column as shown below.

https://i.stack.imgur.com/00Gxw.png

How can i do this?

Snippet of the HTML:

            1 Stop Signs<br />
            480-961-7446<br />
500 N. 56th Street<br />
        Chandler, AZ  85226<br />

<br />
                Website: www.1stopsigns.com<br />
            <br />
            </p><br /><hr><br />

It’s spaced like this in the source of the 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-05-30T09:58:59+00:00Added an answer on May 30, 2026 at 9:58 am

    Assuming the html that shown above is well formed,my approach to this problem must be in 2 phases.
    First. Clear a little bit the html text to be more efficient to export or manage the information. Here try to clear the items you want to save and delete those you know you don’t want to require in the near future.

    $html = preg_replace("|\s{2,}|si"," ",$html); // clear non neccesary spaces
    $html = preg_replace("|\n{2,}|si","\n",$html); // convert more return line to only one
    $html = preg_replace("|<br />|si","##",$html); // replace those tags with this one
    

    Then you’ll have a more clean html to work with similar to this….

    1 Stop Signs##
    480-961-7446##
    500 N. 56th Street##
    Chandler, AZ  85226##
    Website: www.1stopsigns.com##
    ##
    </p>##<hr>##
    

    Second. Now you can explode the fields or make an implode into a comma separate value to form a csv

    // here you'll have the fields to work with into the array called $csv_parts
    $csv_parts = explode("##",$html);
    
    // imploding, so there you have the formatted csv similar to 1 Stop Signs,480-961-7446,..
    $csv = implode(",",$csv_parts);
    

    Now you’ll have a two ways to work with the html for extracting the fields or exporting the csv.


    Hope this helps or give you an idea to develop what you need.

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

Sidebar

Related Questions

I have a database table with a field containing RTF (Rich text Format). I
So I have an array of records retreived from a database. The array is
I have a page called list.php which retrieves from database and shows all the
I have just Extracted the cells from the excel sheet using Apache POI, everything
I have some html extracted to a string var, and want to then use
I have to extract columns from a text file explained in this post: Extracting
I have a table in a Oracle database containing a date field EXPIRYDATE. I
I have the database table logs as the following: alt text http://www.freeimagehosting.net/uploads/16e974703a.jpg I would
I have a PHP script that extract valid GeoJSON data from a database. Now
I have to insert 8000+ records into a SQLite database using Django's ORM. This

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.