# Automatically create links from url/email

**URL:** <https://forum.kirupa.com/t/automatically-create-links-from-url-email/203719>\
**Category:** programming\
**Created:** [October 13, 2006, 1:08pm UTC](https://forum.kirupa.com/t/automatically-create-links-from-url-email/203719 "2006-10-13T13:08:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mentha](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@mentha](https://forum.kirupa.com/u/mentha)\
**Post date:** [October 13, 2006, 1:08pm UTC](https://forum.kirupa.com/t/automatically-create-links-from-url-email/203719/1 "2006-10-13T13:08:44Z")

</div>

Hi there!  
Does anyone have a useful php script for automatically creating links from urls or emailaddresses in a text? I found the following script:

```php
<?php

function makeClickableLinks($text) {

  $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
    '<a href="\\1">\\1</a>', $text);
  $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
    '\\1<a href="http://\\2">\\2</a>', $text);
  $text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
    '<a href="mailto:\\1">\\1</a>', $text);
  
return $text;

}

// Usage

// Email address example
$text = "you@example.com";
echo makeClickableLinks($text);

echo "<br /><br />";

// URL example
$text = "http://www.example.com";
echo makeClickableLinks($text);

echo "<br /><br />";

// FTP URL example
$text = "ftp://ftp.example.com";
echo makeClickableLinks($text);

?>

```

but unfortunately, is a link starts with www. and is also the beginning of a new line of text (so there’s a \<BR\> begore it), it doesn’t work. Which is quite un-useful for when, for example, you want to make a list of links… I don’t ‘get’ the script well enough to edit it myself, so if anyone could give me a hand with this, er even a complete (and working!) script, I’d be really grateful!

Help?
