LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 04-13-2004, 11:49 AM   #1
knickers
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).



Code:
  
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; 
                      do 
                      { 
                              $text_arr[$i] = $row['card_name']; 
                              $selected_text = eregi_replace($text_arr[$i],'[card]'.$i.'[/card]',$selected_text); 
                              $i++; 
                      } 
                      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); 
                      } 
              } 
              $db->sql_freeresult($result); 
      }

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
knickers
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 ...

~cheers
 
  


Reply


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


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

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