NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page preg_replace help needed! lol

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-11-2006, 02:07 PM THREAD STARTER               #1 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



preg_replace help needed! lol


this dosen't seem to work:
PHP Code:
$old_q urldecode($_GET['q']);
????: NamePros.com http://www.namepros.com/programming/196336-preg_replace-help-needed-lol.html
    
$spelling "<b>Spelling Suggestion:</b> <a href=\"search.php?".preg_replace("/q=".urlencode($old_q)."/","q=".urlencode($result['ResultSet']['Result']),$_SERVER['QUERY_STRING'])."\">Did you mean <i><b>".$result['ResultSet']['Result']."</b></i></a><br /><br />"
This is a part of the spell checking script on 6YD search.

Can anyone help me? If $_GET['q'] is one word, then the spell check works a dream - ie: http://www.6yd.net/search.php?q=scool&m=web but when you have two words - ie: http://www.6yd.net/search.php?q=scool+lessons&m=web then it spells it correctly in the link's text, but it dosen't correct it in the url. The link and text are in the variable $spelling by the way.

Tom
PoorDoggie is offline  
Old 05-11-2006, 02:52 PM   #2 (permalink)
NamePros Member
Join Date: Apr 2005
Posts: 117
mikesherov will become famous soon enoughmikesherov will become famous soon enough
 



do the urlencoding after of the preg_replace, not before! I believe that's right.

:-)
mikesherov is offline  
Old 05-11-2006, 02:54 PM THREAD STARTER               #3 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



will have a go... stand by

nope - even as:
PHP Code:
$old_q $_GET['q'];
????: NamePros.com http://www.namepros.com/showthread.php?t=196336
$spelling "<b>Spelling Suggestion:</b> <a href=\"search.php?".preg_replace("/q=$old_q/","q=".urlencode($result['ResultSet']['Result']),$_SERVER['QUERY_STRING'])."\">Did you mean <i><b>".$result['ResultSet']['Result']."</b></i></a><br /><br />"
I still get the same results... The search.php page up on 6yd at the moment has the script above in it, not the origional.

I think it could have something to do with the fact that it is "word+word" in the querystring, but not in a variable or something... anyone got any ideas or a better way of going about it?
PoorDoggie is offline  
Old 05-12-2006, 01:06 PM THREAD STARTER               #4 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



Please help... anyone!
PoorDoggie is offline  
Old 05-12-2006, 01:40 PM   #5 (permalink)
NamePros Regular
Join Date: Mar 2006
Posts: 397
sacx13 is on a distinguished road
 



Thumbs up Reg ex.


I just tested on my computer and is working in this way:

preg_replace("/q=(.+?)&/",'q='.urlencode($result['ResultSet']['Result'])."&",$_SERVER['QUERY_STRING'])

replace your preg_replace with the above one.

Regards
sacx13 is offline  
Old 05-12-2006, 01:41 PM   #6 (permalink)
NamePros Member
Join Date: Apr 2005
Posts: 117
mikesherov will become famous soon enoughmikesherov will become famous soon enough
 



Sorry, I meant you have to url_encode the $_GET[old_q] variable before the replace because the server string will have it encoded, and the get superglobal will have it decoded!

So simply change:
PHP Code:
$old_q $_GET['q']; 
????: NamePros.com http://www.namepros.com/showthread.php?t=196336
to

PHP Code:
$old_q urlencode($_GET['q']); 
and instead of preg_replace, just use str_replace! It is a bit faster and should be used when you're doing a literal replacement instead of a pattern replacement.
mikesherov is offline  
Old 05-12-2006, 02:15 PM THREAD STARTER               #7 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



aha! works - You are a lifesaver!

have some rep
Originally Posted by mikesherov
Sorry, I meant you have to url_encode the $_GET[old_q] variable before the replace because the server string will have it encoded, and the get superglobal will have it decoded!

So simply change:
PHP Code:
$old_q $_GET['q']; 
to

PHP Code:
$old_q urlencode($_GET['q']); 
and instead of preg_replace, just use str_replace! It is a bit faster and should be used when you're doing a literal replacement instead of a pattern replacement.
PoorDoggie is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 04:37 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger