
angelez
Newbie
Dec 7, 2007, 5:51 AM
Post #1 of 1
(132 views)
Shortcut
|
|
[HELP] PHP preg_replace problem
|
Can't Post
|
|
hello guys, i want ask 'bout replace commands on PHP, i have a code to capitalize some special words like l.a. to L.A. or t.v. to T.V. like this:
<? $string = "lead on the way to l.a."; //this example string $str_list = array("l.a.","la","T.v.","t.v.","Tv","tv"); foreach($str_list as $key_str => $val_str) { if(preg_match("/\b$val_str\b/",$string)) { $good_word = strtoupper($val_str); $string = preg_replace("/\b$val_str\b/",$good_word,$string); } } ?> the result should be like this: "lead on the way to L.A." but the result that i see is like this: "L.A. on the way to l.a." :( whats wrong from preg_match and preg_replace command?
<? preg_match("/\bl.a.\b/",$string) // this describe real process //or preg_replace("/\bl.a.\b/",$good_word,$string); ?> may be dot (.) has specific function for preg_match / preg_replace command?(i think too) what is the solution for this? l.a. CHANGE TO => L.A. => is that i want :) not, lead CHANGE TO => L.A. => not like this :( if there no dot (.), the result is right, ex: tv => TV or la => LA is there any other command to process this, please help me "sorry for bad english :)
Anime Lyric * JPop Lyric * Metal, Rock Lyric http://mylyric.6te.net/ Download Lyrics as Text File is available NOW [U
|