can any tell how to remove characters after ? in php. I have one string test?=new i need to remove the characters as well as = from that string.
substr
and strpos
The simplest way to do this is with substr() DOCs and strpos() DOCs.
$string = 'test?=new';
$cut_position = strpos($string, '?') + 1; // remove the +1 if you don't want the ? included
$string = substr($string, 0, $cut_position);
As you can see substr()
extracts a sub-string from a string by index and strpos()
returns the index of the first instance of the character it is searching for (in this case ?
).