Hey, I got part of text , every time different but looks like this '/s4w/1276675395.html' how to extract number (in this case) 1276675395 ? I used preg_replace "/[^0-9]/i" , but then I figure out that in s4w number 4 is present so its doesnt work.
i have this simple function, it might help function get_string_between($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } echo get_string_between('/s4w/1276675395.html', '/s4w/', '.html'); PHP: This should print out 1276675395 best luck
Regex is a Swiss army knife but sometimes the overhead is not needed when a simple string function will work: $var = basename('/s4w/1276675395.html', '.html'); echo $var; // 1276675395 PHP:
I've also made a similar function it's optimized to the max i think. function between($source, $start, $end, $p = 0) { $s = strpos($source, $start, $p) + strlen($start); return substr($source, $s, strpos($source, $end, $s) - $s); } PHP:
function extractOnlyNumbers($source) { $result = ""; $Letter = ""; $valid_chars ="1234567890"; for ($i = 0; $i < strlen($source); $i++) { $Letter = substr($source, $i, 1); if (strstr($valid_chars, $Letter) !== FALSE) $result .= $Letter; } return $result; }