Вопрос

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!

Это было полезно?

Решение

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;

Другие советы

$str = 'lorem ipsum - dolor sit amet!';
$pos = strpos($str,'-');
echo substr($str ,$pos+1,strlen($str));
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top