Text Formatting Functions

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
Bob42
Forum Newbie
Posts: 3
Joined: Thu Jul 09, 2009 10:08 am

Text Formatting Functions

Post by Bob42 »

I don't know if this is the correct forum for this topic but here goes.

I have an application where I want to use a form textarea to enter text, provide the ability to preview the text, similar to blogs, then email the completed message to multiple recipiants.

The problems come in when trying to handle HTML link code (<a href=""></a>) and hard returns. I have experimented a bit with the PHP function htmlspecialchars and have used the PHP mail function where returns must be specified as \n or \r\n.

My question is, does PHP have a function to replace hard returns with \n and is there a way to preserve HTML link code in the final email message or do I have to process the text myself? I would prefer not to implement blog-like capabilities.

Thanks for any help,
Bob
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Text Formatting Functions

Post by social_experiment »

Will this option be available to only you, in the role of admin, or to users in general? If it is only you doing the entering of data, you can leave away the htmlspecialchars() / htmlentities() and add a 'Content-type: text/html' header to send the email as a link. That header will let the email be sent as an html document basically.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Text Formatting Functions

Post by pickle »

Are you sending a plain text email or an HTML email? If plain text, then the hard returns in the textarea will translate to hard returns in the email. Additionally, you won't be able to put <a /> tags in your email & have them parsed.

If you're sending HTML emails, you'll want to look at the nl2br() function.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply