adrianTNT Posted September 6, 2008 Share Posted September 6, 2008 Hello, I did a search, I didn't find something similar... I need a function, maybe someone can help. I need to display a user comment (just like a forum post) and - convert the plain text into a clickable html link - do wordwrap on the visible text but not inside the link tag - do a htmlentities or htmlspecialchars on the text outside of the link This is exactly how Vbulletin posts are processed, liks are clickable and text is wrapped properly to avoid long texts that break site layout. Anyone can help? I am sure some people used this in websites. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/123051-creating-clickable-links-from-user-comment-then-do-wordwrap-and-htmlentities/ Share on other sites More sharing options...
nuttycoder Posted September 7, 2008 Share Posted September 7, 2008 why not use bbcode? then you have full control over what a user can put in their comments http://www.sitepoint.com/article/bb-code-php-application/ Quote Link to comment https://forums.phpfreaks.com/topic/123051-creating-clickable-links-from-user-comment-then-do-wordwrap-and-htmlentities/#findComment-635565 Share on other sites More sharing options...
adrianTNT Posted September 7, 2008 Author Share Posted September 7, 2008 I already have many "user comments" in database and Is best to find a good way to display those instead of using something like BB code. Maybe somone can tell me how to apply a htmlentities on text outside of the <a> tags for this function? How can I do a htmlentities($1) and htmlentities($2) for this code? <?php // converts links inside plain text to clickable <a> tags if (!function_exists("text_to_clickable_link")) { function text_to_clickable_link($text){ # this functions deserves credit to the fine folks at phpbb.com $text = preg_replace('#(script|about|applet|activex|chrome):#is', "$1:", $text); // pad it with a space so we can match things at the start of the 1st line. $ret = ' ' . $text; // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing // Must contain at least 2 dots. xxxx contains either alphanum, or "-" // zzzz is optional.. will contain everything up to the first space, newline, // comma, double quote or <. $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "$1<a href=\"http://$2\" rel=\"nofollow\" target=\"_blank\">$2</a>", $ret); // Remove our padding.. $ret = substr($ret, 1); return $ret; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/123051-creating-clickable-links-from-user-comment-then-do-wordwrap-and-htmlentities/#findComment-635575 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.