How can I cut the string before '(' sign with php
For example: $a = "abc dec g (gold)";
How can I cut the string become only "abc dec g"??
I tried to used this strstr($a, '(', true) but error display.
How can I cut the string before '(' sign with php
For example: $a = "abc dec g (gold)";
How can I cut the string become only "abc dec g"??
I tried to used this strstr($a, '(', true) but error display.
You could do this, using explode
:
list($what_you_want,) = explode('(', $str, 2);
Or you could also do this, using substr
and strpos
:
$what_you_want = substr($str, 0, strpos($str, '('));
The reason you got the error using strstr
is because the last argument is not available unless you have PHP 5.3.0 or later.