![](/img/trans.png)
[英]Converting telephone numbers into “tel:” hyperlinks with regular expression replacement
[英]PHP regular expression to add a href=tel: in front of each telephone number
我是php正则表达式的新手,尽管您能不能帮助我创建一个有效的php正则表达式,以便为每个电话号码添加“ a”标签。
每个电话号码都有此掩码:
+39 0000 00 00 00
这应该像:
<a href="tel:+39 0000 00 00 00">+39 0000 00 00 00</a>
我已经花了很多时间在网上搜索它,所以我决定在这里提出这个问题。
嗨,您可以使用preg_replace添加一些后缀:
preg_replace('/(\+[0-9 ]{16})/', '<a>$1</a>', "+39 0000 00 00 00")
\\+
表示+,而[0-9 ]{16}
表示数字和空格的精确16个字符。如果您有15 {min,max}
或更短的时间,可以写{min,max}
表示不包括+的字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.