escaping ' and " from templates files and user entered variables (forms to mail)
| From: | Vempyre | Date: | Thu, 27 Jul 2000 21:45:36 +0000 |
| Subject: | escaping ' and " from templates files and user entered variables (forms to mail) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-8673@lists.php.net to get a copy of this message | ||
in the following code, which take a template (who is placed in $arr_t1 or $arr_t2, and contains
plain text AND html code), fill it with the info from a form (transforms {{variable}} to $variable
from the form), to be emailed with mail() to a given receiver :
(code source from formit, by Rudy Nooyen)
$domail = 1;
while ($domail <= $nr_mail):
if ($domail == 1) $var2use = $arr_t1; else $var2use = $arr_t2;
for ($index = 0; $index < count($var2use); $index++)
{
$pattern = ereg("{{[A-z0-9_]*}}", $var2use[$index]);
if ($pattern)
{
$line = ereg_replace("{{","$",$var2use[$index]);
$line = ereg_replace("}}","",$line);
}
else
{
$line = $var2use[$index];
}
$line = addslashes($line) . "<br>";
eval( "\$line = \"$line\";" );
if ($index == 0 && $domail == 1) $linetot1 = $line;
elseif ($index > 0 && $domail == 1) $linetot1 .= $line;
if ($index == 0 && $domail == 2) $linetot2 = $line;
elseif ($index > 0 && $domail == 2) $linetot2 .= $line;
}
++$domail;
endwhile;
In the resulting mail, all ' are replaced by \\ if coming from the form variables (and text
following \\ is removed for that line) and all ' from the template text are replaced by
\\' (but this time text following is shown)
all " from templates are replaced by \" (which destroys my hrefs links) and are simple not
displayed if coming from the form variables(with following text not displayed)
what function could I use in my code for all ' and " to be displayed in the resulting mail
messages??? It screws up the display in teh email message body, and since I need some html links in
the template, I need the " to show up properly, and since the form contain addresses, which
often have ', this one also need to be correctly ouput in the email
using :
PHP4.0.1.pl2 win32
apache 1.3.12 win32