HTML Encoding

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lilalfyalien
Forum Newbie
Posts: 6
Joined: Tue Apr 06, 2010 7:37 am

HTML Encoding

Post by lilalfyalien »

Hi,

I have a scenario where I am expecting a user to enter HTML in a box. I then want to process this to make sure that if they have put special characters e.g. &, ", ' etc that these are correctly encoded. I cannot work out what to do because there is an htmlentities() function but this will also convert the "<" & ">" in the html tags e.g. "<span>". How do I only encode the text within the html tags?

My ultimate goal is to allow users to copy and paste from MS Word into an iframe which is editable. MS Word at the moment is putting the normal junk in when the users copy and paste and I need it cleaned.

Thanks in advance,

Lilalfyalien
lilalfyalien
Forum Newbie
Posts: 6
Joined: Tue Apr 06, 2010 7:37 am

Re: HTML Encoding

Post by lilalfyalien »

Oh, I've just spotted the double_encode parameter... I'll give that a go!
lilalfyalien
Forum Newbie
Posts: 6
Joined: Tue Apr 06, 2010 7:37 am

Re: HTML Encoding

Post by lilalfyalien »

Oh no double_encode didn't work :(

It converted "<br />" into "<br />"- not what I wanted!
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: HTML Encoding

Post by omniuni »

Pasting from Word is a terrible terrible idea, but if you must have it, check out:

http://www.bioinformatics.org/phplabwar ... /index.php

It's a script called htmlLawed, and it has a lot of useful functions including options to TRY to clean up Word's mess.
lilalfyalien
Forum Newbie
Posts: 6
Joined: Tue Apr 06, 2010 7:37 am

Re: HTML Encoding

Post by lilalfyalien »

I know! I'm trying to integrate it into a CMS and a lot of people insist on typing it up in Word first!

This was just what I was looking for- thanks!
roders
Forum Commoner
Posts: 68
Joined: Tue Oct 20, 2009 9:29 am

Re: HTML Encoding

Post by roders »

Post Reply