tags:

views:

72

answers:

3

for example the string is my name is xyz(25) i want to get 25 in a variable through php..

A: 

Use regular expressions.

Deniz Dogan
+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
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
This will only work for integer values. This will do:$exploded = explode("(", "xyz(25)");$exploded = explode("(", "exploded[1]");$return = exploded[0];
Residuum