Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-13-2004, 11:49 AM   #1
LQ Newbie
Registered: Jun 2003
Posts: 5

Rep: Reputation: 0
Speeding up the script, or the SQL Query?

Ok first of all. I'll explain what I'm trying to achieve.

This is a little script that will take a post similar to this one, and from a list of cards from a table in the database, compare it and if the words match, then it will add a [card]MATCHED WORD[/card] ([card] tags around the matched word).

if ( !empty($selected_text) ) 
              $sql = "SELECT card_name 
                      FROM " . CARDS_TABLE . " 
                      ORDER BY length(card_name) DESC"; 

              if ( !($result = $db->sql_query($sql)) ) 
                      message_die(GENERAL_ERROR, 'Could not obtain search results', '', __LINE__, __FILE__, $sql); 

              if ( $row = $db->sql_fetchrow($result) ) 
                      $i = 0; 
                              $text_arr[$i] = $row['card_name']; 
                              $selected_text = eregi_replace($text_arr[$i],'[card]'.$i.'[/card]',$selected_text); 
                      while ( $row = $db->sql_fetchrow($result) ); 

                      for($j = 0; $j < $i; $j++) 
                              $selected_text = str_replace('[card]'.$j.'[/card]','[card]'.$text_arr[$j].'[/card]',$selected_text); 

I tested the SQL query and it's not the slow part. Now it's the eregi_replace. I wanted to use str_replace but it's case sensitive and str_ireplace is only available in PHP5 (I'm using PHP4).

So, I need some way to speed up the egeri_replace while loop.

Am I doing this as fast as possible?
Is there any way I could speed this search and replace up?

Can anyone help me?

Sorry if my english is bad.
Old 04-13-2004, 11:57 AM   #2
LQ Newbie
Registered: Jun 2003
Posts: 5

Original Poster
Rep: Reputation: 0
preg_replace is FASTER than eregi_replace

I figured out how to make it faster ....

You can delete this wheneever, sorry for wasting anyone's time ...



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL query performance smaida Programming 6 06-08-2005 09:22 AM
SQL query help pls. vickr1z Programming 8 10-18-2004 11:25 PM
Massive SQL Query patpawlowski Programming 7 03-05-2004 04:24 PM
ColdFusion - Using a script to build and execute SQL query when a button is clicked Locura Programming 1 02-25-2004 09:59 PM
SQL Query question oulevon Programming 7 01-16-2004 01:50 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:59 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration