when posting a new message on my forum and it contains a url. How do i automatically add the bbcode url tags to a url in the message?

Recommended Answers

All 3 Replies

do a php explode between http:// and a space, and between www. and a space.
add the <a href=" and </a>
Fairly straightforward
akternatively:

I suggest you use a wysiwyg editor such as openwysiwyg
and turn off the features you don't need.

remember if you are allowing html tags make sure people can't enter javascript or iframes or images from other sites etc.

read my tutorial on hacking at http://www.effectivewebdesign.co.nz/tutorial.php

hope this helps :)

thanks for the help... i'm trying this but it is not working. It doesn't turn the text into a hyperlink.

$info = mysql_real_escape_string($_POST['content']);

$data = preg_replace('/\[url\](.+?)\[\/url\]/', '<a href="$1">$1</a>', $info);

echo $data;

$info is e.g. www.google.com ... when i put mouseover it , it's not a hyperlink

try this

<?php
$string = mysql_real_escape_string($_POST);
$pattern[0] = "%(http|https|ftp)(://.*?)%";
$pattern[1] = "%((http|https|ftp)(://.*?)(jpg|bmp|gif|jpeg|png))%";
$replacement[0] = "<a href=\"\$1\$2\">\$1\$2</a>";
$replacement[1] = "<img src=\"\$1\" />";for($i = 0; $i <= 1; $i++){
$string = preg_replace($pattern[$i],$replacement[$i],$string);
}
?>
this should work and stop img links stuffing up

Hope this helps :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.