I’m trying to remove from a string everything start with / char, so if I have
my_value/j/im<b*+èo[/h>e\ylo
I’d like to remove the string /j/im<b*+èo[/h>e\ylo and return only my_value.
I thought to use something with str_replace but I’m not a great regex programmer and I’m doing practise with php.
function clean_value ($value) {
return preg_replace ("^(/.*?)$", "", $value);
}
How can I do?
There is no reason to use regex here. Use a combo of
strpos()andsubstr()instead:The above will work if you can guarantee that the string will always have at least 1
/character in it. If you can’t guarantee that or don’t know, simply modify to: