【发布时间】:2018-04-08 17:28:00
【问题描述】:
我在玩一个基本功能,想知道下面是不是一种将纯文本转换为可点击电话链接的特别有效的方法?
该函数将假设以下纯文本场景:
- 01234 123 456
- +44 1234 123 456
- +44 (0) 1234 123 456
函数如下:
function pd_convert_tel_number($tel) {
if (substr( $tel, 0, 1 ) === '0') {
$tel = '<a href="tel:+44'.ltrim(str_replace(' ', '', $tel), '0').'">'.$tel.'</a>';
} else if(strpos($tel, '+44') !== false || strpos($tel, '(0)') !== false) {
$tel = '<a href="tel:'.str_replace(array( '(0)', ' ' ), '', $tel).'">'.$tel.'</a>';
} else {
$tel = '<a href="tel:"'.$tel.'">'.$tel.'</a>';
}
return $tel;
}
【问题讨论】: