GD77 Posted July 18, 2012 Share Posted July 18, 2012 Hello: I'm using the following to format a number: $ne=1113444555 $v1=substr($ne, 0,3)."-".substr($ne, 3,1)."-".substr($ne, 4,3)."-".substr($ne, 7); result: 111-3-444-555 Trying with preg_replace... not working well since I can find the match but not successful in converting it: $v1=preg_replace('/(([(\d]{3}){1}([(\d)]{1}){1}([(\d)]{3}){2})/', '$1-$2-$3-$4', $ne); Quote Link to comment https://forums.phpfreaks.com/topic/265890-preg_replace-issue/ Share on other sites More sharing options...
GD77 Posted July 18, 2012 Author Share Posted July 18, 2012 fixed with: '~([(\d]{3}){1}([(\d)]{1}){1}([(\d)]{3}){1}([(\d)]{3}){1}$~', '$1-$2-$3-$4',.... but I m using ([(\d)]{3}){1} twice should not that be replaced with ([(\d)]{3}){2}? :/ anyway here how I ve fixed it http://www.functions-online.com/preg_replace.html online test still don t egt it why ~ delimiter is obligatory in it :/ Quote Link to comment https://forums.phpfreaks.com/topic/265890-preg_replace-issue/#findComment-1362388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.