sameer manek sameer manek - 9 months ago 28
PHP Question

PHP seperating numbers from string into an array

I am trying to seperate numbers from a string like this:
-4-25-30 with php

I have tried following things:

$fltr = array();
for($i=0;$i<count($q);$i++) {
$odr = $q[$i]['odr'];
$fltr = preg_match_all('/([a-z0-9_#-]{4,})/i', $odr, $matches);

this one gives an output: 1

and the explode funtion:

$fltr = array();
$odr = $q[$i]['odr'];
$fltr = explode($odr, '-');

note: $odr contains the string.

this one gives an O/P: "-"

I want to fetch all the numbers from the string, please help


Try this

$fltr = explode('-', trim($odr, '-'));

I think you mixed up the delimiter with the actual string when using explode().