I have the following code
$s = '\n email@example.com \n ';
$s = str_replace('\n', '', $s);
echo ord(substr($s, 0, 1));
You need to place the \n in double quotes. Inside single quotes it is treated as 2 characters '\' followed by 'n'
Try below code:
$s = "\n firstname.lastname@example.org \n"; $s = str_replace("\n", '', $s); echo $s;