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;
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!
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));