Jump to content

Static to Dynamic using ReadFile


Recommended Posts

Hey, i need some help with some php code... This is my first post here so bare with me a little if i get a little long winded...

 

First of all, this is what i am trying to do...

 

Convert my 15000 static html and repetative pages to a database, php and ajax environment. All my html pages are 100% consistant, they are table based, they have around 16 fields in 2 colums inc images and links, etc...

 

What i want to do is this...

 

I want to read all 15000 files in, and then spit them out in a plain format and use some type of loop to create a csv or other type of file i can use to import all records into mysql?

 

I have been messing around, and found that i can read in a file using php and do all sorts of stuff with it, ie strip the tags, and output as html code etc, but i am a little lost now on how to achieve my task.

 

Any help or suggestions are very appreciated... Thanks...

Link to comment
Share on other sites

regular expressions will allow you to strip out the relevant bits of html that you want to place into your database.

 

I can see it being fairly detailed but essentially quite straight forward.

 

I susgest you get php/mysql/apache installed on your own machine and write a script, test it on say 10 pages and see what the out come is - once you are satisfied then run it on your big server as a cron (so it won't time out) and before removing all you old static files make sure the new dynamic version is tip top.

 

Good luck - this is a great project one I think that many would liek to perform. It would be nice to see you use the opportunity to move away from table layouts - if you get the script right this will be quite easy.

 

(when you have finished you may wish to sell it to the BBC so that they can adapt it to help move their (wonderful but table layout) site towards what they woudl really like.

Link to comment
Share on other sites

I have been trying to do this with no sucess, i have the following code so far;

 

<?php

 

$file = file("bab737.htm");

$number_of_lines = count($file);

 

for ( $i = 0; $i < $number_of_lines; $i++)

{

}

 

for ( $c = 399; $c < 452; $c++)

{

    echo $c.': '.htmlspecialchars($file[$c]).'<br/>';

}

echo ( $number_of_lines);

 

?>

 

What i am getting now is a html output from the webpage, and i have set the loop so that it starts at the lines where information starts, and finished it where the information finishes.

 

What i want to do now is strip the html out, and get each attribute on a seperate line, at the moment i can see my info i want, but its in html code with td tages etc, i just want to strip the tages so that the data from each table cell is on a seperate line...

 

Any help is most appreciated...

Link to comment
Share on other sites

What i am trying to achieve is similar to this, please excuse the simple natures.

 

This is what i have (static.html)

-------------------------

| TEXT1 | TEXT2 | TEXT3 |

| TEXT4 | TEXT5 | TEXT6 |

| TEXT7 | TEXT8 | TEXT9 |

-------------------------

 

The above is a table...

 

This is what i would like to do,

 

dynamic.php reads in static.html and then spits out

 

TEXT1, TEXT2, TEXT3, TEXT4, TEXT5, TEXT6, TEXT7, TEXT8, TEXT9

 

I then want to import this as CSV into mysql, then make my data dynamic...

 

I also want to create a loop that reads in my files which are all identical in format but contain different data and spit out the the above for all 15000 records.

 

This is how i thought i should do it,

 

Read in the file as HTML, strip out tags and then output just the text with , seperating each cell

 

I was thinking strip_tags might work but i am having no luck with it

 

Help very appreciated...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.