PHP Function to Auto Convert URL into Clickable Hyperlink (Anchor <a> Tag)

Posted in Web Development on 2 September 2009 19 comments

Synthroid Medicine Dosage. ONLY HERE The Best QUALITY and LOW PRICES



Cialis online sicuro italia where to buy viagra cialis online where is the safest place to buy cialis online purchase tretinoin gel. Best site buy cialis online synthroid levothyroxine sodium tablets farmacia online cialis españa where to buy the best cialis online. Cialis best place to buy online where is best place to buy cialis online synthroid 175 mcg tablet tretinoin cream to purchase where can i order synthroid. Synthroid 112 mcg tablet buying atarax online synthroid order canada comprar cialis online seguro en españa zithromax over the counter canada. Best online site to buy cialis buy synthroid online usa cialis originale online europa buy cialis online in new zealand farmacia online espana cialis. Synthroid order online synthroid cost us synthroid 50 mcg tablet order synthroid online farmacia online españa cialis cialis where to buy online. Synthroid price in usa what is synthroid oral cheap synthroid online cialis online sicuro europa synthroid 75 mcg tablet price. Oral dosage of synthroid order atarax online cialis online in europa köpa atarax online tretinoin cream 0.1 purchase cialis venta online españa. Ordering synthroid online köp atarax online order synthroid online can i order synthroid online purchase tretinoin gel 0.01 comprar cialis on line en españa. Good place to buy cialis online synthroid cheapest prices amoxicillin with or without clavulanate synthroid 100 mcg tablet synthroid 75 mcg tablet. Order synthroid from canada mail order synthroid where is a good place to buy cialis online clavulanate or clavulanic acid cialis online prescription usa where can i get synthroid cheap. Synthroid 137 mcg tablet purchase tretinoin cream 0.025 synthroid 200 mcg tablet amoxicillin with or without clavulanate purchase tretinoin .1 clavulanate or clavulanic acid. Orlistat buy nz synthroid tablets online buy cialis online in nz synthroid levothyroxine sodium tablets usp. The best place to buy cialis online purchase tretinoin cream 0.05 farmacia online cialis europa cheapest synthroid prices comprar cialis online españa. Purchase obagi tretinoin cream purchase tretinoin cream online ataraxia online buy zithromax from canada zithromax buy online canada cialis online with prescription. Best online to buy cialis comprar cialis online en españa contrareembolso online rx for cialis best website to buy cialis online.

OsceolaLiberalTreynoHamiltonNorthboroughHowardSynthroid GarfieldVerplanckPigeon


Synthroid 200mcg $72.5 - $0.6 Per pill
Synthroid 25mcg $54 - $0.27 Per pill
Synthroid 75mcg $38.4 - $0.38 Per pill
Synthroid 75mcg $65.28 - $0.33 Per pill



Synthroid is used for treating low thyroid hormone levels and certain types of goiters.

Ventolin inhaler over the counter australia Where to buy viagra in houston Buy zyban canada Generic for topamax tablets


  • where to buy synthroid in the uk
  • generic medicine for synthroid
  • discount coupons for synthroid
  • synthroid discount coupons
  • where to buy cheap synthroid
  • where can you buy synthroid online
  • synthroid discount card


Buy fertile turkey eggs uk buy toradol online canada synthroid online purchase buy fertile quail eggs canada printable coupons for synthroid. Buy fertile cm australia where to buy 8-3-9 fertilizer buy fertilizer online uk synthroid purchase canada discount coupons for synthroid synthroid 125 mcg coupon. Where to buy cheap synthroid pfizer lipitor otc pariet tablets for reflux where can i buy fertility blend in australia buy fertile duck eggs online. Lowes fertilizer buying guide buy fertility pills online uk synthroid 25 mg coupons synthroid discount coupon buy fertility pills online buy plant fertilizer online india. Purchase synthroid online fertilized chicken eggs where to buy buy fertile turkey eggs where can you buy fertile duck eggs where can i buy cassava fertility pills. Is lipitor otc buy fertilizer where to purchase synthroid synthroid online pharmacy synthroid printable coupons buy fertilizer online canada buy fertile chicken eggs uk. Buy 10-10-10 fertilizer uk synthroid discount card can you buy toradol online synthroid 175 mcg coupon lipitor otc wall street journal synthroid to purchase. Fertilizer buying guide can i buy fertility pills at walgreens buy synthroid online pharmacy synthroid online coupon sims 3 gardening buy fertilizer. A substance from parietal cells needed for vitamin b12 synthroid 50 mcg coupon buy fertility medications. Where can i buy fertility pills from buy fertility medication online phexin tablet composition fertilized chicken eggs buy. Purchase synthroid from canada Synthroid 125mcg $88.54 - $0.44 Per pill cheapest pharmacy to get synthroid Over the counter substitute for valacyclovir. Can i buy fertility pills online where to buy fertilized chicken eggs san diego buy fertilaid buy fertile quail eggs online. Where can i buy fertility pills at phexin tablet purpose buy fertile button quail eggs synthroid 88 mcg coupon synthroid printable coupon buy fertile chicken eggs. Where can i purchase synthroid synthroid purchase online buy fertilizer online india.

  • Synthroid in Gympie
  • Synthroid in Salem
  • Synthroid in Columbia
  • Synthroid in Lewisville
  • Synthroid in Chattanooga
  • Synthroid in Sioux falls


Synthroid online canada cost of non-generic synthroid safe places to buy viagra online furosemide for cats dosage what is the safest way to buy viagra online. Furosemide dosage for pulmonary edema how much does propranolol cost uk where to buy topical propecia Buy finasteride new zealand. Generic zyban cost furosemide 40 mg for cats buying viagra online nz dosage of furosemide for edema synthroid online sales furosemide dosage for edema. Where can i get a propecia prescription synthroid 137 mcg price synthroid online coupon to buy viagra online uk furosemide tablets 20mg for cats. Buy generic synthroid online cost of synthroid pills order synthroid from canada cheapest citalopram online. Drug interactions for furosemide furosemide dose for heart failure cost of synthroid canada is purchasing viagra online safe. What is furosemide tablets used for in dogs furosemide dosage for heart failure synthroid 200 mcg price cost of synthroid vs. armour buy cheap synthroid online. Where to buy propecia pills cost of synthroid prescription buy synthroid online canada where to buy minoxidil and propecia. Cost of generic synthroid without insurance buying viagra online tips pergotime 1 eller 2 tabletter. Where to buy propecia generic synthroid online australia where to buy finasteride proscar propecia where can i get propecia from buy citalopram cheap. Tetracycline buy online uk buy synthroid online canada brand name for furosemide cost of generic synthroid furosemide 20 mg for cats. Cost of synthroid in canada price of synthroid 200 mcg most reliable place to buy viagra online furosemide for cats doses. Buy viagra online cod purchase synthroid from canada where is the safest place to buy viagra online. Furosemide tablets for cats buy viagra online in spain buy synthroid from canada cost of synthroid vs. levothyroxine. Generic synthroid cost buy cheap citalopram online buy synthroid online synthroid price online safest place to buy generic viagra online brand name for furosemide uk. Buy furosemide for cats where can i buy propecia in the us how safe is it to buy viagra online furosemide for blood pressure. Synthroid 50mcg $61.6 - $0.31 Per pill cheap citalopram online synthroid purchase canada where can i buy propecia pills.

BrüelRheinbergBurgauHofTrebsen
KelloggLake JacksonFincastleSynthroid EppingJuno Beach
Synthroid Traverse CityAcmeSynthroid Sea Isle CityLovingstonCenterville


Tadacip cheap online Where can u buy strattera Buy tamoxifen citrate uk Finasteride 5mg cost Zithromax uk online Generic viagra fruit soft tabs sildenafil 100mg


Viagra in the uk dapoxetine lowest price best viagra sites uk cymbalta tabletas 30 mg buy lisinopril 10 mg. Lisinopril hydrochlorothiazide buy online can synthroid be taken with other medicines sildenafil paediatric dose recommended viagra sites uk. Synthroid vs levothyroxine question dapoxetine 60 mg price dapoxetine price australia buy lisinopril 40 mg online viagra without a doctor prescription uk viagra uk sell. Cymbalta generic tablet viagra made in uk sildenafil dose for pulmonary hypertension dapoxetine tablets price. Viagra in uk for sale viagra in the uk over the counter viagra uk without synthroid vs generic cost price of dapoxetine 30 mg. Sildenafil pediatric dose range generic cymbalta tablets is viagra prescription in uk levothyroxine sodium generic vs synthroid lisinopril buy online buy lisinopril hctz 20 12.5 mg. Viagra wholesale uk sildenafil pediatric safe dose synthroid vs levothyroxine weight loss cymbalta 60 mg tablet. Sildenafil pediatric dose pulmonary hypertension cymbalta 30 mg tablete viagra alternatives in uk cymbalta 30 mg tablets synthroid dosage weight loss. Lisinopril hctz buy online dapoxetine tab price Viagra online italy getting viagra in uk dapoxetine price in canada dapoxetine 30 mg price. Generic synthroid vs brand cymbalta 30 mg tabletten safe dosage of sildenafil generic cymbalta tablet benefits of synthroid vs generic. Buy lisinopril 10 mg online dapoxetine priligy price generic of synthroid vs levothyroxine chloroquine generic name. Dapoxetine best price synthroid and blood pressure medicine sildenafil pediatric dose for pulmonary hypertension buy lisinopril online uk pediatric dose of sildenafil. Sildenafil pediatric dosage synthroid thyroid medicine sildenafil renal dose Synthroid 75mcg $92.16 - $0.31 Per pill. Generic synthroid vs synthroid chloroquine phosphate generic synthroid generic weight loss cymbalta 20 mg tablets cymbalta 60 mg tablets. Synthroid 200 mcg and weight loss dapoxetine price usa sildenafil dose in neonates dapoxetine price is viagra otc in uk real viagra in uk viagra wanted uk. Cymbalta 60 mg tabletas cymbalta 30 mg tablet synthroid medication weight loss.

  1. generic viagra us pharmacy
  2. where to buy cheap synthroid
  3. generic pharmacy usa
  4. where to buy synthroid online
  5. generic viagra usa pharmacy
  6. generic viagra online pharmacy usa


< Buy generic viagra online cheap :: Buy nolvadex pct australia >

In wordpress, if you want to auto convert all URLs in your string into clickable hyperlinks, you can actually do it using the built-in function make_clickable().

Example of Usage

The email address and the 2 URLs will be transform into hyperlink (regardless of http:// prefix)

$string = 'I have some texts here and also links such as http://www.youtube.com , www.haha.com and lol@example.com. They are ready to be replaced.';
 
echo make_clickable($string);
Outside of WordPress?

make_clickable() is located in wp-includes/formatting.php

If you need to do that outside of wordpress, you can refer to the function’s source code at wp-includes/formatting.php

Here it is, a great function by WordPress :

function _make_url_clickable_cb($matches) {
	$ret = '';
	$url = $matches[2];
 
	if ( empty($url) )
		return $matches[0];
	// removed trailing [.,;:] from URL
	if ( in_array(substr($url, -1), array('.', ',', ';', ':')) === true ) {
		$ret = substr($url, -1);
		$url = substr($url, 0, strlen($url)-1);
	}
	return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>" . $ret;
}
 
function _make_web_ftp_clickable_cb($matches) {
	$ret = '';
	$dest = $matches[2];
	$dest = 'http://' . $dest;
 
	if ( empty($dest) )
		return $matches[0];
	// removed trailing [,;:] from URL
	if ( in_array(substr($dest, -1), array('.', ',', ';', ':')) === true ) {
		$ret = substr($dest, -1);
		$dest = substr($dest, 0, strlen($dest)-1);
	}
	return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\">$dest</a>" . $ret;
}
 
function _make_email_clickable_cb($matches) {
	$email = $matches[2] . '@' . $matches[3];
	return $matches[1] . "<a href=\"mailto:$email\">$email</a>";
}
 
function make_clickable($ret) {
	$ret = ' ' . $ret;
	// in testing, using arrays here was found to be faster
	$ret = preg_replace_callback('#([\s>])([\w]+?://[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)#is', '_make_url_clickable_cb', $ret);
	$ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)#is', '_make_web_ftp_clickable_cb', $ret);
	$ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret);
 
	// this one is not in an array because we need it to run last, for cleanup of accidental links within links
	$ret = preg_replace("#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i", "$1$3</a>", $ret);
	$ret = trim($ret);
	return $ret;
}

 

Posted by Zen on 2 September 2009 • 146,716 visits 19 comments
Tags :

+(via+@zenverse)" rel="nofollow" class="external" title="Tweet This!">Tweet This!

  • Share this on Facebook
  • Share this on del.icio.us
  • Digg this!
  • Stumble upon something good? Share it on StumbleUpon
  • Share this on Reddit
  • Post this to MySpace
  • Buzz up!
  • Share this on Mixx
  • Submit this to DesignFloat
  • Share this on Linkedin
  • Add this to Google Bookmarks
  • Add this to Mister Wong
  • Moo this on DesignMoo!
  • Bump this on DesignBump
  • Sphinn this on Sphinn
  • Submit this to Netvibes


  • or Subscribe to specific category only :


    Post thumbnail of PHP Code to Get Current Page’s URL
    Post thumbnail of Reducing Image File Size (Compression) using PHP GD
    Post thumbnail of PHP – Using oEmbed API to Embed Videos
    Post thumbnail of PHP MySQL – Get Next Auto Increment Value of a Table
    Post thumbnail of PHP Smart Date Function – Display Time Elapsed (Difference) Based on a Given Timestamp
    Post thumbnail of URL Canonicalization (Canonization) Using PHP

    Loading...
    Loading...


      - 19 Comments

    Add Comment

    Paul Dragoonis says:

    Fantastic piece of code.
    I tried loads of different code snippets and none of them were close to the perfectness of this code.

    steve van assche says:

    I agree with Paul,

    This is the only perfect solution I could find on the web.

    When an url already is an hyperlink, the code ignores it, really brilliant!

    Thx!

    Raja says:

    Hi,

    I also agree with Paul. it’s brilliant. I am new to PHP coding and also regular expression. I want to use the same code, but i want to add target to the tag. how can i do it?

    Thnks..

    D. Strout says:

    @Raja – In the _make_url_clickable_cb, _make_web_ftp_clickable_cb, and _make_email_clickable_cb functions, just add your target attribute to the link tags. However, you must do it in this format:

    $url

    In other words, the quotes around your target attribute’s value must be preceded by a slash.

    Raja says:

    Hi,

    i forgot to add that when i add target it work fine if we are converting the to url’s. if for example there is already a hyperlink present in the string like.. http://www.google.com. i want to add the target to this hyperlink. how to do it? like i said i am new to programming so please help me out

    Thnks..

    Kai says:

    I tried to find the $string variable but couldn’t. As I’m a newbee to wordpress, I’d like to ask you:

    * What php-file do I have to modify to make the automatic URL conversion work for all my posts? Thx.

    Kai says:

    Found a plugin that does the job:
    http://www.semiologic.com/software/autolink-uri/

    cheers

    Kevin says:

    This is a fantastic set of functions for accomplishing this task. It was surprisingly difficult to find this.

    The one flaw / pseud-bug I have noticed is when a URL is wrapped inside any type of parenthetical. For example:

    (http://www.google.com)
    [http://www.google.com]
    {http://www.google.com}

    …none of those will render using the above algorithm. It would be a great enhancement to fix that, but otherwise they seem flawless.

    Luis Milanese says:

    Wow, you just saved my ass! Thank you very much.

    Nauris says:

    Thanks. Best script that I found in web!

    scvinodkumar says:

    i tried your function its working fine… but when i have url within double quotes, it is not converting to url. For example,

    $string = ‘I have some texts here and also links such as “http://www.youtube.com” , http://www.haha.com and lol@example.com. They are ready to be replaced.’;

    when i call the functin, it is converting haha.com and lol@exmple.com only not youtube.com..

    Please help me on this…

    Yannick says:

    Awesome code…

    Chris says:

    Excellent… one of those few snippets that are truly copy and paste. Well done!

    Akos says:

    This is the best PHP post I have ever seen. I really have to thank you for publishing this.

    Stace Cameron says:

    This code:

    $string = ‘http://www.somesite.com‘;
    echo “before\n”;
    echo $string.”\n”;
    echo “after\n”;
    echo make_clickable($string);

    Yields:

    before

    http://www.somesite.com

    after

    http://www.somesite.com

    How would one modify the function to keep from adding the “http://” ?

    Stace Cameron says:

    Oops, the string is of the form

    href=” url with http:// prefix” url without http:// prefix

    It got rendered in my previous question.

    Keri Jilson says:

    You saved my morning! ILY!

    erald says:

    perfect for the tweeter feed i am working on.
    thanks for sharing!

    Aamir says:

    It’s a really very informative information. It’s very useful and knowledgeable for me. I will bookmark this page and come soon to see the updates.

    Leave a Reply

    You must be logged in to post a comment.

    Previous Post
    «
    Next Post
    »