php - Regex not getting whole link at special characters -


i using code:

$string = preg_replace("~(?!(?:https?://(?:www\.)?|www\.)(?:youtube\.com)(?:https?://(?:www\.)?|www\.)[\w./=?#-]+~i", '<a href="$0">$0</a>', $string); 

so can turn link beneath clickable link.

http://upload.wikimedia.org/wikipedia/commons/f/f2/bill_clinton%2c_yitzhak_rabin,%2c_yasser_arafat_at_the_white_house_1993-09-13.jpg 

this works part... makes link of http://upload.wikimedia.org/wikipedia/commons/f/f2/bill_clinton rest stays plain text. how can make work whole link? see comma too... how can make link?

also i'm trying account punctuation @ end of url (so don't include it).

<?php  $string = "this works http://upload.wikimedia.org/wikipedia/commons/f/f2/bill_clinton%2c_yitzhak_rabin%2c_yasser_arafat_at_the_white_house_1993-09-13.jpg. 1 should fail http://www.youtube.com/v/adlskdfjasopie. although 1 should fail http://youtu.be/adlkajdaslk.";  $string = preg_replace("~(?!(?:https?://(?:www\.)?|www\.)(?:youtu))(?:https?://(?:www\.)?|www\.)[^\s]+[^.!?,\<\]\[\)(]~i",'<a href="$0">$0</a>',$string);   ?> 

output

this works <a href="http://upload.wikimedia.org/wikipedia/commons/f/f2/bill_clinton%2c_yitzhak_rabin%2c_yasser_arafat_at_the_white_house_1993-09-13.jpg. ">http://upload.wikimedia.org/wikipedia/commons/f/f2/bill_clinton%2c_yitzhak_rabin%2c_yasser_arafat_at_the_white_house_1993-09-13.jpg. </a>this 1 should fail http://www.youtube.com/v/adlskdfjasopie. although 1 should fail http://youtu.be/adlkajdaslk. 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -