PHP HTML Entities

Soldato
Joined
16 Dec 2005
Posts
14,443
Location
Manchester
I have created my own function for converting BBCode into XHTML, as can be seen below. I have successfully managed to convert all BBCode tags and also add paragraph <p> tags where necessary.

The next step is to convert quotes, brackets <> and other characters to their corresponding HTML Entity. However, I am unsure as to how to do this. I know about the htmlspecialchars() and htmlspecialentities() functions but I don't think they would work well with existing HTML.

For instance, it would end up converting quotes inside or <a> tags would convert angle br...e { return false; } } [/CODE]
 
Looks good, and a lot more comprehensive. However, could you tell me how it deals with quotes in the BBCode, such as [noparse]blahblah[/noparse] and so on?

If I were to do htmlspecialchars on the above I would get:

Code:
[noparse][url=& quot ;blahblah& quot ;][/url][/noparse]
Similarly if I did htmlspecialchars on XHTML it would wreck all the tags.
 
Just been looking and I notice you don't need to put quotes in! :p

So all I have to do is whack in a htmlspecialchars at the beginning of my function and im sorted. Amazing what you overlook.
 
Back
Top Bottom