scottybwoy Posted March 20, 2009 Share Posted March 20, 2009 How do I write a regex to strip quotes from an sql query if it contains numbers. i.e. '1234', '2', '23' becomes 1234, 2, 23. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/150311-quoted-numbers-preg_replace/ Share on other sites More sharing options...
effigy Posted March 20, 2009 Share Posted March 20, 2009 $sql = preg_replace("/'(\d+)'/", '$1', $sql); Quote Link to comment https://forums.phpfreaks.com/topic/150311-quoted-numbers-preg_replace/#findComment-789536 Share on other sites More sharing options...
scottybwoy Posted March 23, 2009 Author Share Posted March 23, 2009 Thanks, So is the $1 the returned number from the preg_replace? Quote Link to comment https://forums.phpfreaks.com/topic/150311-quoted-numbers-preg_replace/#findComment-791636 Share on other sites More sharing options...
.josh Posted March 24, 2009 Share Posted March 24, 2009 yes, but it only works within the pattern or within the 2nd argument of preg_replace. You can't turn around do for instance $num = $1; If you want to be able to do something like that, then you need to use preg_match or preg_match_all and it will be assigned to an array specified in the 3rd argument. Quote Link to comment https://forums.phpfreaks.com/topic/150311-quoted-numbers-preg_replace/#findComment-792233 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.