[PHP] help using ereg_replace()

2002-01-14 Thread Erik Price

Hello everyone,

I am trying to learn how to use ereg_replace(), but I don't seem to be 
doing it correctly.

$phone is a 10-digit string.

I want to perform the following:

$phone = ereg_replace(.{10}, [part where I am confused], $phone);

I would like the output to be

$phone = (555) 555-;

Can a regexp guru help me out? Thank you


Erik


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] help using ereg_replace()

2002-01-14 Thread Jimmy

Hi Erik,

 $phone is a 10-digit string.
 I would like the output to be
 $phone = (555) 555-;

you don't need regex to do that.
just insert add ( to the beginning of $phone,
add )  to the 4th position,
and - to the 4th position from behind,
using substr_replace() function.

anyway if you insist on using regex:
preg_replace(/(\d{3})(\d{3})(\d{4})/, (\\1) \\2-\\3, $arr);

--
Jimmy

Everything loses its value when overly used, including love.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]