Connecting Tech Pros Worldwide Help | Site Map

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

Member
 
Join Date: Feb 2007
Location: malaysia
Posts: 51
#1: Feb 23 '07
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})/";
Member
 
Join Date: Feb 2007
Posts: 99
#2: Feb 23 '07

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


Quote:

Originally Posted by Fareast Adam

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.
Member
 
Join Date: Feb 2007
Location: malaysia
Posts: 51
#3: Feb 26 '07

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


Quote:

Originally Posted by xwero

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...
Member
 
Join Date: Feb 2007
Location: malaysia
Posts: 51
#4: Feb 26 '07

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


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?
Member
 
Join Date: Feb 2007
Posts: 99
#5: Feb 26 '07

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


Quote:

Originally Posted by Fareast Adam

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.
Member
 
Join Date: Feb 2007
Location: malaysia
Posts: 51
#6: Feb 26 '07

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


Quote:

Originally Posted by xwero

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?
Member
 
Join Date: Feb 2007
Posts: 99
#7: Feb 26 '07

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


[PHP]
$text = preg_replace('/ ([a-z]{1})/', strtoupper('$1'),$text);
[/PHP]
Member
 
Join Date: Feb 2007
Location: malaysia
Posts: 51
#8: Feb 26 '07

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


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
Member
 
Join Date: Feb 2007
Posts: 99
#9: Feb 26 '07

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


[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?
Member
 
Join Date: Feb 2007
Location: malaysia
Posts: 51
#10: Feb 27 '07

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


Quote:

Originally Posted by xwero

[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?
Member
 
Join Date: Feb 2007
Location: malaysia
Posts: 51
#11: Feb 27 '07

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


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
Member
 
Join Date: Feb 2007
Location: malaysia
Posts: 51
#12: Feb 27 '07

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


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
Reply