View Full Version : Replace the word "and"
02-16-2010, 10:24 PM
Im trying to get the preg_replace to replace the word and but cant seem to get it to work :confused:
preg_replace('/ And /i',' og ',$firstname) ;
02-16-2010, 10:27 PM
Hi, try this:
preg_replace('/\sand\s/i',' og ',$firstname) ; :thumbsup:
02-16-2010, 10:43 PM
Thank you very mutch :thumbsup:
Can you also tell me if i can combine multi replace in one command ??
$firstname = preg_replace('/\sog\s/i',' og ',$firstname);
$firstname = preg_replace('/\sand\s/i',' and ',$firstname);
$firstname = preg_replace('/\svon\s/i',' von ',$firstname);
$firstname = preg_replace('/\svan\s/i',' van ',$firstname);
Yes it may look wierd but i have a
$firstname = mb_convert_case(trim($_POST["firstname"]), MB_CASE_TITLE, "utf-8");
to make shure the names are with capital letters .. but those word i dont want to be capital
02-16-2010, 10:50 PM
$firstname = preg_replace('/\s(og|and|von|van)\s/ie','" ".strtolower("\\1")." "',$firstname); didn't tested but should works :)
oops,code edited, because you want to output spaces before and after the string...
02-16-2010, 11:00 PM
Aha ..( not [ :o
That strtolower is smart :thumbsup:
Ill try it out
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.