lfirth1959
asked on
RegEx ASP to PHP Conversion
I want to convert the following function I use in asp/vbscript to PHP. All it does is take a 10 digit phone number like 0312341234 and adds spaces to it so that it's more readable on the screen like 03 1234 1234.
Function PhoneNum(intValue)
Dim strRetValue, RegEx
Set RegEx = New RegExp
RegEx.pattern = "(\d{2})(\d{4})(\d{4})"
RegEx.Global = True
strRetValue = RegEx.Replace(intValue, "$1" & " " & "$2" & " " & "$3")
PhoneNum = strRetValue
End Function
Function PhoneNum(intValue)
Dim strRetValue, RegEx
Set RegEx = New RegExp
RegEx.pattern = "(\d{2})(\d{4})(\d{4})"
RegEx.Global = True
strRetValue = RegEx.Replace(intValue, "$1" & " " & "$2" & " " & "$3")
PhoneNum = strRetValue
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
function phoneNum($string) {
$pattern = '/(\d{2})(\d{4})(\d{4})/';
$repl = '$1 $2 $3';
echo preg_replace($pattern, $repl, $string );
}
?>
<?php
$phoneNum = "0312341234";
phoneNum($phoneNum);
?>