|
Posted by Simon Harris on 02/04/07 23:29
Norman,
Thank you very much. I will give this a go.
Simon.
"Norman Peelman" <npeelman@cfl.rr.com> wrote in message
news:45c5e5a6$0$18883$4c368faf@roadrunner.com...
> 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]}<br>";
> $stripped = strip_tags($data[$loop]);
> echo "$stripped<br>";
> }
>
> ---
>
> Norm
--------------------------------------------------------------------------------
I am using the free version of SPAMfighter for private users.
It has removed 3496 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!
[Back to original message]
|