Re: [PHP] parsing text for special characters



Adam Williams wrote:
I've got an html form, and I have PHP parse the message variables for
special characters so when I concatenate all off the message variables
together, if a person has put in a ' " or other special character, it

exactly how are ' and " special inside the body of an email message?

won't break it when it used in mail($to, "MMH Suggestion", "$message",
"$headers"); below is my snippet of code, but is there a better way to
parse the text for special characters. what about if I were to have the

it's not 'parsing' - it's 'escaping', and how you escape depends on the context
in which the string is going to be used.

$message inserted into a mysql field? how would I need to handle
special characters that way?

mysql_real_escape_string()


$need_message = $_POST['need_message'];

function flash_encode($need_message)
{
$string = rawurlencode(utf8_encode($need_message));

$string = str_replace("%C2%96", "-", $need_message);
$string = str_replace("%C2%91", "%27", $need_message);
$string = str_replace("%C2%92", "%27", $need_message);
$string = str_replace("%C2%82", "%27", $need_message);
$string = str_replace("%C2%93", "%22", $need_message);
$string = str_replace("%C2%94", "%22", $need_message);
$string = str_replace("%C2%84", "%22", $need_message);
$string = str_replace("%C2%8B", "%C2%AB", $need_message);
$string = str_replace("%C2%9B", "%C2%BB", $need_message);

return $need_message;
}

where is this function used and why would you 'flash encode' a string
destined for the body of an email?


//and then there are $topic_message, $fee_message, etc and they all get
concatenated with
$message .= needs_message;

this line is wrong, unless 'needs_message' is actually a constant.

$message .= $topics_message;
$message .= $fee message;

this line is a parse error. have you actually tried to run your code?


//emails the $message
mail($to, "MMH Suggestion", "$message", "$headers");

^-- why are these variables inside quotes?


.



Relevant Pages

  • parsing text for special characters
    ... I've got an html form, and I have PHP parse the message variables for special characters so when I concatenate all off the message variables together, if a person has put in a ' " or other special character, it won't break it when it used in mail; below is my snippet of code, but is there a better way to parse the text for special characters. ...
    (php.general)
  • Re: [PHP] parsing text for special characters
    ... special characters so when I concatenate all off the message variables ... parse the text for special characters. ... or you want to encode it first. ...
    (php.general)
  • how to concatenate two strings and maintain new lines and white spaces???
    ... I want to concatenate two strings each of them might contain white ... spaces, special characters and new lines, how to concatenate them ... without truncating these chars?? ...
    (comp.lang.tcl)
  • Re: test for "special characters" in text
    ... >I need to make sure that a cell contains NO SPECIAL CHARACTERS (including ... Function foo(s As String, ... own invalid entries that caused the errors. ...
    (microsoft.public.excel.worksheet.functions)
  • [PATCH 2/2] tracing/filters: support for operator reserved characters in strings
    ... Because the operators and parentheses have a higher precedence ... than the operand characters, which is normal, then we can't ... Then after this patch you can still declare string condition like ... support strings with special characters for tracing filters] ...
    (Linux-Kernel)