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 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); 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? 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. Link to comment https://forums.phpfreaks.com/topic/150311-quoted-numbers-preg_replace/#findComment-792233 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.