If i have a string like so:
Hello - Bye
How can i make php find and delete a specifc character and the rest of the string on wards
like an example
Hello - Bye
find the character -
and be left with the string
Hello
If i have a string like so:
Hello - Bye
How can i make php find and delete a specifc character and the rest of the string on wards
like an example
Hello - Bye
find the character -
and be left with the string
Hello
Use strpos
to find the position of the first occurence of a substring and then substr
to just get everything up to that position:
$pos = strpos($str, '-');
if ($pos !== false) { // strpos returns false if there is no needle in the haystack
$str = substr($str, 0, $pos);
}
And if you have PHP 5.3 and later, you could also use the strstr
function with the third parameter set to true.