TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   preg_replace (http://www.talkphp.com/general/3268-preg_replace.html)

Jako 08-22-2008 04:22 AM

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.

delayedinsanity 08-22-2008 05:12 PM

PHP Code:

$name preg_replace "'($query)'is" "<b>$1</b>" $row'player_last' ] ); 


Jako 08-22-2008 06:14 PM

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

What does the $1 change to fix this?

xenon 08-22-2008 08:19 PM

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


All times are GMT. The time now is 05:30 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0