preg replace - preg_replace remove only the word after @ -


i'm trying remove username in string. tried code below removes after @

$string = 'he @username die'; $string = preg_replace('/@.*/','',$string);  echo $string; // output: 

i want output be: die

thanks

use \s means not space character (the opposite of \s) instead of .:

$string = 'he @username die'; $string = preg_replace('/@\s+/','',$string);  echo $string; // output:  die 

you may want remove following space:

$string = 'he @username die'; $string = preg_replace('/@\s+\s*/','',$string);  echo $string; // output: die 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -