I am wondering if it is possible to remove only =20 from the end of multiple lines within a block of text? This is for my e-mail to ticket gateway. When a reply is received and contains multiple "=20" I want to remove them. However I want to leave =20 intact if it is legitimately part an e-mail (such as a URL). An example of an incoming e-mail:
$correspondence = <<<EOF
Hello=20
=20
Thank you for getting back to me.=20
The link you need is http://domain.com/index.php?id=204726 .=20
Regards=20
EOF;
This is quoted-printable encoding, which uses =
followed by hex codes to encode special characters in plain text. Use quoted_printable_decode
to decode a message that's encoded this way. You shouldn't have to worry about literal =20
anywhere in the text, because it should be encoded as =3D20
(=3D
is the encoding for the =
sign), and you'll get back the original =20
when it's decoded.
You can do it using the discard technique with a regex like this:
http://.*=20$(*SKIP)(*FAIL)|=20
The idea behind this regex is to discard what matches the (*SKIP)(*FAIL)
and to keep the =20
. So, for your case above regex will discard the links.
You can see in the Substitution
section the expected output.
The php code:
$re = "/http.*=20$(*SKIP)(*FAIL)|=20/m";
$str = "\$correspondence = <<<EOF
Hello=20
=20
Thank you for getting back to me.=20
The link you need is http://domain.com/index.php?id=204726 .=20
Regards=20
EOF;";
$subst = "";
$result = preg_replace($re, $subst, $str);