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.
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.
Then you’ll have a more clean html to work with similar to this….
Second. Now you can explode the fields or make an implode into a comma separate value to form a csv
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.