TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-22-2008, 04:22 AM   #1 (permalink)
The Wanderer
 
Join Date: Jun 2005
Posts: 21
Thanks: 1
Jako is on a distinguished road
Default preg_replace

Quick question...

I got preg_replace working how I wanted when used in a search query.

So the variable is bolded in the returned results.

PHP Code:
$name preg_replace "'($query)'is" "<b>$query</b>" $row'player_last' ] );
        
$name =  ucwords($name); 
Issue is, if I search for "ja", Jako would be returned as jako instead of Jako.

ucwords doesn't seem to fix that issue after I just used preg_replace.
Jako is offline  
Reply With Quote
Old 08-22-2008, 05:12 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

PHP Code:
$name preg_replace "'($query)'is" "<b>$1</b>" $row'player_last' ] ); 
delayedinsanity is offline  
Reply With Quote
Old 08-22-2008, 06:14 PM   #3 (permalink)
The Wanderer
 
Join Date: Jun 2005
Posts: 21
Thanks: 1
Jako is on a distinguished road
Default

Sweet, it worked. Thanks a lot for your help.

What does the $1 change to fix this?
Jako is offline  
Reply With Quote
Old 08-22-2008, 08:19 PM   #4 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

$1 says "just copy the first captured group into a variable called $1", which is the first reference of the captured group, so you don't have to copy and paste that expression every time you need to use it. Every groups that are captured (are between paranthesis), are numbered, in the order they match, starting from 1.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Reply



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

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:44 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design