Here it is. Simply and easily.
$text = "text text text @hello text text "; $a = strstr($text, '@'); // отсекаем всё слева $pos = strpos($a, " "); // узнаём сколько знаков до пробела справа $final = substr($a, 0, $pos); // отступим $pos количество символов, и удалим всё справа echo $final;
Here is even easier:
$text = "text text text @hello text text "; $a = strstr($text, '@'); // обрезаем все слева до @ $b = strstr($a, ' ', true); // если true, то обрезка будет справа, обрезаем после пробела echo $b;
A shortened view: (author @E_p)
$text = "text text text @hello text text "; $a = strstr(strstr($text, '@'), ' ', true); echo $a;
strstr(strstr($text, '@'), ' ', true);- E_p