Question

How can I remove the "-" in my string?

$text  = 'lorem ipsum - dolor sit amet!';
$lorem = strstr($text, '-');

echo $lorem;

return:

- dolor sit amet!

And I need this:

dolor sit amet!

Was it helpful?

Solution

This is simple enough to use explode(). Use list() with it to make it a one-liner and give the variable a clear name (i.e. not use array syntax like $parts[1]).

list(,$dolor) = explode(' - ', $text);
echo $dolor;

OTHER TIPS

$str = 'lorem ipsum - dolor sit amet!';
$pos = strpos($str,'-');
echo substr($str ,$pos+1,strlen($str));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top