davidb52 Posted August 18, 2011 Share Posted August 18, 2011 hello this is my code:$query2 = mysql_query("SELECT blog FROM users WHERE id='" . mysql_real_escape_string( $ido ) . "'");while($row2 = mysql_fetch_array($query2)){$data[] = $row2;foreach ($data as $row2);$blog = $row2['blog'];echo htmlentities($blog);}I use htmlentities so people can't use <b >bold< / B> tags.But how I grab links and make them clickable.like:this is my holiday,first day we started here google.comNice picture's huh?but what i want:this is my holiday,first day whe started here google.comNice picture's huh?How can I make something like that? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 18, 2011 Share Posted August 18, 2011 Are you saying you want to escape all HTML entities except those for links? Link to comment Share on other sites More sharing options...
davidb52 Posted August 18, 2011 Author Share Posted August 18, 2011 Are you saying you want to escape all HTML entities except those for links?yes Link to comment Share on other sites More sharing options...
justsomeguy Posted August 18, 2011 Share Posted August 18, 2011 You might want to use strip_tags instead of htmlentities, and tell it to keep <a> tags.http://www.php.net/manual/en/function.strip-tags.php Link to comment Share on other sites More sharing options...
davidb52 Posted August 18, 2011 Author Share Posted August 18, 2011 You might want to use strip_tags instead of htmlentities, and tell it to keep <a> tags.http://www.php.net/manual/en/function.strip-tags.php yeah I now,but I mean dumb people can have text like:(what user can put in, this is what in database)this is a test look here ttp://google.com (I notice if i put htt(p) it also makes automatic a link, thats what I want but that it also works with al these example's)this is a test look here www.google.comthis is a test look here google.comand makes it clickable(what the site echo)this is a test look here http://google.comthis is a test look here www.google.comthis is a test look here google.comsorry for bad english (I'm from the Netherlands) Link to comment Share on other sites More sharing options...
justsomeguy Posted August 18, 2011 Share Posted August 18, 2011 Oh, you want it to make automatic links, not remove HTML. You'll need to use a regular expression, there are several examples online for finding URLs.http://www.google.com/search?client=opera&...channel=suggest Link to comment Share on other sites More sharing options...
davidb52 Posted August 19, 2011 Author Share Posted August 19, 2011 really thank you!i'm using: $message = preg_replace(" #((http|https|ftp)://(\S*?\.\S*?))(\s|\;|\)|\]|\[|\{|\}|,|\"|'|:|\<|$|\.\s)#ie", "'<a href=\"$1\" target=\"_blank\">$3</a>$4'", htmlentities($message));echo $message; <b >BOLD etc doesn't work exactly what I want</ b> and links with (h)ttp://google.com become http://google.comthis is good now,not really necessary but is there a script for just google.com www.google.com? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 19, 2011 Share Posted August 19, 2011 You could write a pattern to look for ".com" or ".net" or whatever, plus any characters other than whitespace that come before and after it and assume it's a URL. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.