for example the string is my name is xyz(25) i want to get 25 in a variable through php..
+3
A:
use preg_match to do it:
$string = "xyz(25)";
preg_match("/.*\((\d*)\)/", $string, $matches);
print_r($matches);
will return
Array ( [0] => xyz(25) [1] => 25 )
phalacee
2009-06-25 07:42:25
A:
I think skurpur/phalacee solutions are the most flexible/best approaches, however I found two others:
<?php
$exploded = explode("(", "xyz(25)");
$yourint = (int)$exploded[1];
?>
<?php
$exploded = (int)substr(strchr("xyz(25)","("), 1);
?>
merkuro
2009-06-25 07:44:20
This will only work for integer values. This will do:$exploded = explode("(", "xyz(25)");$exploded = explode("(", "exploded[1]");$return = exploded[0];
Residuum
2009-06-25 08:00:44