Hello,
I've been trying to figure out the best solution for what I need to do. I think it's simple enough, just need direction.
Ultimately, I need to handle posted info just like these forums.
What I need to do is this:
When a user posts to my site, I need:
1. Any HTML code to be visible as code.
2. Urls to be converted to clickable links.
3. Safely allow single and double quotes.
I've been using htmlentities, and htmlspecialchars, but I'm not getting the right result.
Any help would be greatly appreciated. This is already eating up too much time.
Thanks!
How to handle posted HTML and URLS
Moderator: General Moderators
1.
2.
3.
Code: Select all
$submission = str_replace("<", "<", str_replace (">", ">", $submission));Code: Select all
$submission = ereg_replace('[a-zA-Z]+://([.]?[a-zA-Z0-9_/?:#+=&-])*', "<a href=\"\\0\">\\0</a>", $submission );
$submission = ereg_replace('(^| )(www([.]?[a-zA-Z0-9_/?:#+=&-])*)', "\\1<a href=\"http://\\2\">\\2</a>", $submission );Code: Select all
$submission = addslashes($submission);- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
html_special_chars may be of interest. It'll handle everything aside from the URLs automatically becoming links.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
To quote the php manual...
...preg_replace() which uses a Perl-compatible regular expression syntax, is often a faster alternative to ereg_replace()...