sameer manek sameer manek - 1 year ago 79
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

Answer Source

Try this

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download