iamcal / lib_autolink

PHP HTML link formatting library
MIT License
63 stars 22 forks source link

Feature: autolink_phone numbers #18

Open timbunch opened 5 years ago

timbunch commented 5 years ago

First off, thank you so much for this! I wanted to drop a note in here to see if you thought it would be quickly doable to extend this to also replace phone numbers. I'm currently doing this with my own simple regex and preg_replace. Would be so cool to have it in here as well!

My second rate PHP:

function autolink_phone($text) { $text = preg_replace("/\d?(\s?|-?|\+?|\.?)((\(\d{1,4}\))|(\d{1,3})|\s?)(\s?|-?|\.?)((\(\d{1,3}\))|(\d{1,3})|\s?)(\s?|-?|\.?)((\(\d{1,3}\))|(\d{1,3})|\s?)(\s?|-?|\.?)\d{3}(-|\.|\s)\d{4}/i", "<a href=\"tel:$0\" target='_blank'>$0</a>", $text); return ($text); }