usman usman - 2 months ago 6
PHP Question

Getting numbers only from an array

i have this array in php

$name = array("page18.jpg","page16.jpg","page17.jpg","page19.jpg",);


i wanted to strip all alphabets and dots in the string remains only number like

$name = array("18","16","17","19");


how do i achieve that can some one please guide me how to do it in PHP language

Answer

Try this,use preg_replace

$name = array("page18.jpg","page16.jpg","page17.jpg","page19.jpg",);
foreach($name as $val)
{
    $new_name[] = preg_replace('/\D/', '', $val);
}

DEMO