Jump to content

Recommended Posts

(Sorry for the double post. I just realized I posted it in the math forum by mistake)

 

I have created a very simple blog application and would like to add the functionality of having hyperlinks automatically created when a url is entered. For instance, when I post a blog entry with something like "Go to www.foobar.com", I would like it to automatically add the anchor tags (like this site does.)

 

Any ideas?

 

Thanks

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/140234-automatic-hyperlinking/
Share on other sites

[tex]never noticed this tag whats this do?[/tex]

 

^^ a personal test lol.. but besides that let me write up something

 

but you have to study some regex its very neat :P

 

/((?:www\.|https?:\/\/)[.a-z0-9;&?\/-]+?)/i

thats really really simple but should do your job (havn't tested it)

 

--------------

wowie that tex thing is sweet lol

<?php
$text = "omg hey go to http://www.lovinglori.com/signatures.php www.google.com its so cool!";
function link($a,$b) {
	if ($a == 'http://' || $a == "https://") {
		return "<a href='{$b}'>$b</a>";
	}
	else {
		return "<a href='http://{$b}'>$b</a>";
	}
}
echo preg_replace("/((www\.|https?:\/\/)[.a-z0-9;&?\/-]+)/ie","link('\\2','\\1')",$text);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.