I would like to extract whatever text comes inside (). Desired output should be "Name", "Turkey". I have tried this
$input = "This is (Name). I live in (Turkey). and so on with other brackets as well". $unit = extract_unit($input, '(', ')'); echo $unit; function extract_unit($string, $start, $end) { $pos = stripos($string, $start); $str = substr($string, $pos); $str_two = substr($str, strlen($start)); $second_pos = stripos($str_two, $end); $str_three = substr($str_two, 0, $second_pos); $unit = trim($str_three); // remove whitespaces return $unit; }
But Only getting first output which is "Name" but require "Turkey" and so on values whatever comes in brackets if the length of text increases.