PHP Function convert string to skype link
posted 1 year ago
Here is a PHP function that will convert all phone numbers in a string to buttons that when pressed pull open Skype and try to call the number.
Here is an example on
Startthehunt.com: http://montreal.startthehunt.com/apt/105
The user submits their phone number in their classified listing and it automatically turns it into a link.
<?php
function makeSkype($phone) {
$phone = eregi_replace('([0-9]+.[0-9]+.[0-9][0-9][0-9][0-9])', '<a href="skype:+1-\1"><img src="images/skype.gif" alt="Call using Skype" title="Call using Skype" border="0" /> \1</a>', $phone);
$phone = eregi_replace('([0-9]+[0-9]+[0-9][0-9][0-9][0-9])', '<a href="skype:+1-\1"><img src="images/skype.gif" alt="Call using Skype" title="Call using Skype" border="0" /> \1</a>', $phone);
return $phone;
}
// USE ANY STRING FROM A POST OR DATABASE
$string = "My Number is 514-555-5555.";
// CALL FUNCTION
$string = makeSkype($string);
// ECHO FUNCTION
echo $string;
?>
Change the "img" link to where your skype logo is located on your server and you can right click and save this skype logo:
*note: this function only works with the phone pattern (555-555-5555 & 555-5555)
