if the string is
$abc = "hello @john what are you doing";
How to get john
from string. word after @
sign. Maybe regex is used but I can't figure out how this can be done. For I know how to change specific word using str_replace()
but I'm not getting how to get that specific word after @
sign.
$abc = "hello @john what are you doing";
$found = preg_match('/@([^-\s]*)/', $abc, $matches);
$name = null;
if ($found) {
$name = $matches[1];
}
Use a regular expression with a capture group.
preg_match('/@(\w+)/', $abc, $match);
$name = $match[1];