|  | Posted by Norman Peelman on 02/05/07 04:03 
Norman Peelman wrote:> Simon Harris wrote:
 >> Hi All,
 >>
 >> I have a page which loops through many database records, running a
 >> string function to strip HTML (Using RegEx/preg_replace). I am
 >> concerned that over time, this is going to become very slow.
 >>
 >> Few ideas I had:
 >>
 >> a) Cache the HTML free version of the text in the DB,
 >> updating/creating each records text when the page is loaded, based on
 >> the updated date of the record.
 >> b) Is there a faster way to strip the HTML? Could I do this on-the-fly
 >> at mySQL level?
 >> c) In ASP ( My native language! :-) ) I can load the results into an
 >> array, then loop the array which is quicker. Can this be done in PHP?
 >>
 >> Any ideas much appreciated.
 >>
 >> Simon.
 >>
 >>
 >
 >   Yes, you can do the same in PHP. It can be done like so:
 >
 > $dbc = mysql_connect('localhost','user','passwword');
 > $db = mysql_select_db('database',$dbc);
 >
 > $query = "SELECT * FROM tablename WHERE ????"; // you get the idea. :)
 > $result = mysql_query($query,$dbc);
 >
 > // grab rows into array $data with associative keys
 > while($data[] = mysql_fetch_array($result,MYSQL_ASSOC)
 > {
 > }
 >
 > // subtract 1 as an extra row still gets created when the final
 > mysql_fetch_array fails.
 > $data_size = count($data)-1;
 >
 > // loop through data
 > for($loop = 0;$loop <= $data_size; $loop++)
 > {
 echo "{$data[$loop]['field_name']}<br>";
 >   $stripped = strip_tags($data[$loop]['field_name']);
 >   echo "$stripped<br>";
 > }
 >
 
 
 Simon,
 
 I made a simple mistake... take note of corrections within the for..loop.
 
 Norm
  Navigation: [Reply to this message] |