By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,348 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,348 IT Pros & Developers. It's quick & easy.

php pattern for text (if there is any dot found set a single space for next word!)

P: 51
Here is my code:

//capture name from textfield
$name = $_POST['name'];

//make pattern for name
function checkName($uname)
$pattname = "/^[a-z\.\s]+$/";
return preg_match($pattname,$uname);

//display error for invalid name
echo "$nama invalid name!";
//display formated name if name is valid
echo "Your name: ".ucwords(strtolower(wordwrap($nama)))." (after formated!)";

My problem is i can't make a pattern for short name like "M.Micheal" where if there is any dot(.) found set a single space for next word after dot (M. <space>Micheal OR M. Micheal). Is that possible to using ereg_replace() function?
Feb 28 '07 #1
Share this Question
Share on Google+
2 Replies

P: 51
I have been completed, here is the solution...

//just add str_replace() function like below
echo "Your name: ".ucwords(strtolower(wordwrap(str_replace(".", ". ",$name))))." (after formated!)";
Feb 28 '07 #2

Expert 2.5K+
P: 4,258
When you want people to help you, enclose your shown code within php or code tags!!

Read the Posting Guidelines before you show any more code in this forum.

Feb 28 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.