I have tried to remove an email sign which is @ from a string like this:
$string = @james_dy; //OR:
$string = @smartsge130;
etc. using the followings:
$string1 = preg_replace('/[^p{L}p{N}s]/u', '', $string);
Or:
$string1 = str_replace('@', '', $string);
without a success.
Please advise how to do that.
2
Answers
I can confirm that both my codes work really well; they did not work previously due to a wrong variable used for showing after trying for an hour before posting for help here. But I prefer the second option removing only @. Many thanks
Both your method (
preg_replace
andstr_replace
) work well.If you meet an error, it may be caused by syntax mistake, and it should be:
One should keep in mind that PHP need strings in quotes.