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
Post a Comment