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

php pattern problem for xxxxxx-xx-xxxx using all digits

P: 51
hi all... anybody here know how to set a php pattern for xxxxxx-xx-xxxx using all digits? here is my code, is there any mistake?
$pattic="/(\d{6})-(\d{2})-(\d{4})/";
Feb 23 '07 #1
Share this Question
Share on Google+
11 Replies


P: 99
hi all... anybody here know how to set a php pattern for xxxxxx-xx-xxxx using all digits? here is my code, is there any mistake?
$pattic="/(\d{6})-(\d{2})-(\d{4})/";
have you tried "/^([0-9]{6})-([0-9]{2})-([0-9]{4})$/" ?

It should be the same with \d but sometimes the php functions don't interpret the escaped characters.
Feb 23 '07 #2

P: 51
have you tried "/^([0-9]{6})-([0-9]{2})-([0-9]{4})$/" ?

It should be the same with \d but sometimes the php functions don't interpret the escaped characters.
It look loke a charm! Thanks...
Feb 26 '07 #3

P: 51
Other sample, firstly i want to capture all the text from the textfield then insert into db. Before inserting into db, i have to convert all text that have been captured before into standard english grammer (first letter must be start with big caps).. How can i do that? Any idea?
Feb 26 '07 #4

P: 99
Other sample, firstly i want to capture all the text from the textfield then insert into db. Before inserting into db, i have to convert all text that have been captured before into standard english grammer (first letter must be start with big caps).. How can i do that? Any idea?
I think you better use css for this sort of thing. text-transform :capitalize will do the trick but if you insist on doing it the php way

[PHP]preg_replace('/ ([a-z]{1})/', strtoupper('$1'),$string); [/PHP]

I haven't tested it but the though behind it is fairly simple : every first little letter after a space has to transform to a capital letter.
Feb 26 '07 #5

P: 51
I think you better use css for this sort of thing. text-transform :capitalize will do the trick but if you insist on doing it the php way

[PHP]preg_replace('/ ([a-z]{1})/', strtoupper('$1'),$string); [/PHP]

I haven't tested it but the though behind it is fairly simple : every first little letter after a space has to transform to a capital letter.
is that like this to write?

function convertText($text)
{
preg_replace('/ ([a-z]{1})/', strtoupper('$1'),$text);
}

but how can i pass and it insert into db? is that need any return variable to do that?
Feb 26 '07 #6

P: 99
[PHP]
$text = preg_replace('/ ([a-z]{1})/', strtoupper('$1'),$text);
[/PHP]
Feb 26 '07 #7

P: 51
I try this just for a testing:

if(isset($_REQUEST['Submit']))
{
$text = $_POST['name'];
$string = preg_replace('/ ([a-z]{1})/', strtoupper('$1'),$text);
echo $string;
}

but i dont achieves my point.
ex: when i insert text "web programming" but i dont get the actual output like "Web Programming" - an output must be big caps for any first word and both word seperate with single space!

Thanks xwero at all! I cant reply u later, just send it regards bye :p
Feb 26 '07 #8

P: 99
[PHP]

if(isset($_REQUEST['Submit']))
{
$text = $_POST['name'];
// for the first letter
$string = preg_replace('/^([a-z]{1})/', strtoupper('$1'),$text);
// for all following words
$string = preg_replace('/ ([a-z]{1})/', strtoupper('$1'),$text);
echo $string;
}
[/PHP]

Which output do you get now?
Feb 26 '07 #9

P: 51
[PHP]

if(isset($_REQUEST['Submit']))
{
$text = $_POST['name'];
// for the first letter
$string = preg_replace('/^([a-z]{1})/', strtoupper('$1'),$text);
// for all following words
$string = preg_replace('/ ([a-z]{1})/', strtoupper('$1'),$text);
echo $string;
}
[/PHP]

Which output do you get now?
Sorry buddy i still not get an expected result! For example i type a text "web programming" but what i get is "webprogramming".. Do u have any idea?
Feb 27 '07 #10

P: 51
I got the solution from http://www.weberdev.com/ViewArticle/479. Here is what i want:

if(isset($_REQUEST['Submit']))
{
//capture text from textfield
$text = $_POST['name'];

//function ucwords() set any first capital in any words with capital letter
echo ucwords($text);
}

Thanks again xwero!

Regards,
Fareast Adam
Feb 27 '07 #11

P: 51
Here is really what i wants;

if(isset($_REQUEST['Submit']))
{
//capture text from textfield
$text = $_POST['name'];

//convert all text into lowercase then set all any first capital in any words with capital letters
//function ucwords() set any first capital in any words with capital letter
//function strtolower() set all text into lowercase
echo ucwords(strtolower($text));
}

Regards,
Fareast Adam
Feb 27 '07 #12

Post your reply

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