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

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -