473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help - stripping special characters from email and retaining html tags

I want to send html formatted text yet strip out special characters
(e.g. quotes and semi colons). I've seen preg_replace examples like
$messageout = preg_replace('/[^0-9a-z\[\]\(\)<>]/i','',$message); to
preserve some additional characters but don't know how to approach
preserving html in general.

This is a typical message line: $message.= "<b>Date: </b>" . $today .
"<br />";

I am setting these headers:

$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers.= "From: $emailaddress\r\n";

Also, where can I find out which characters need to be escaped?

Please advise.

Thank you!
- Tim

Oct 8 '07 #1
2 3808
Big Moxy wrote:
I want to send html formatted text yet strip out special characters
(e.g. quotes and semi colons). I've seen preg_replace examples like
$messageout = preg_replace('/[^0-9a-z\[\]\(\)<>]/i','',$message); to
preserve some additional characters but don't know how to approach
preserving html in general.

This is a typical message line: $message.= "<b>Date: </b>" . $today .
"<br />";

I am setting these headers:

$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers.= "From: $emailaddress\r\n";

Also, where can I find out which characters need to be escaped?
not sure i am getting what you are asking here, but htmlspecialchars()
perhaps? http://php.net/htmlspecialchars

--
Posted via a free Usenet account from http://www.teranews.com

Oct 8 '07 #2
On Oct 8, 1:10 pm, Justin Koivisto <justin.koivi...@gmail.comwrote:
Big Moxy wrote:
I want to send html formatted text yet strip out special characters
(e.g. quotes and semi colons). I've seen preg_replace examples like
$messageout = preg_replace('/[^0-9a-z\[\]\(\)<>]/i','',$message); to
preserve some additional characters but don't know how to approach
preserving html in general.
This is a typical message line: $message.= "<b>Date: </b>" . $today .
"<br />";
I am setting these headers:
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers.= "From: $emailaddress\r\n";
Also, where can I find out which characters need to be escaped?

not sure i am getting what you are asking here, but htmlspecialchars()
perhaps?http://php.net/htmlspecialchars

--
Posted via a free Usenet account fromhttp://www.teranews.com- Hide quoted text -

- Show quoted text -
I'm sorry I didn't state my objective for the post. Thank you for
telling me about htmlspecialchars. I believe it is applicable in this
case but not sure. My goal is to add defensive coding for whatever the
user may intentionally or unintentionally type in and still preserve
the html formatted email that has been created. Should I converse my
initially formatted message with htmlspecialchars and then apply
preg_replace to it? If so, which of these special characters require a
preceding "escape" character -@ , . & ; -

Thanks!
Oct 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Martin | last post by:
I have a HTML parser that reads product pages from various retailers - and I want to optimize it somewhat: I download all HTML before I start the parsing - and to do that I want to: - Get rid...
6
by: Ralph Freshour | last post by:
I'm taking text from a textarea object and want to strip out characters other than A-Za-z0-9 before I send the data to MySQL table - is there a function I can use to do this in PHP? Thanks...
4
by: Michael Vilain | last post by:
Originally, I was using $value =~ s/<.*>//g; to strip HTML tags from a variable. It actually stripped everything from the first "<" to the last ">" after the ending tag. I found this regex...
3
by: Jens Kristensen | last post by:
I have a problem displaying a divbox containing a html-textarea - everything works fine with "normal" characters. However, when the textarea contains special chars like <P> or ' , the box fails to...
15
by: Jeff North | last post by:
Hi, I'm using a control called HTMLArea which allows a person to enter text and converts the format instructions to html tags. Most of my users know nothing about html so this is perfect for my...
258
by: Terry Andersen | last post by:
If I have: struct one_{ unsigned int one_1; unsigned short one_2; unsigned short one_3; }; struct two_{ unsigned int two_1;
4
by: Lu | last post by:
Hi, i am currently working on ASP.Net v1.0 and is encountering the following problem. In javascript, I'm passing in: "somepage.aspx?QSParameter=<RowID>Chèques</RowID>" as part of the query...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.