如何删除“ 0”。 &&quot”从PHP中的电话号码

发布于 2025-01-31 15:27:34 字数 378 浏览 2 评论 0原文

必须删除电话号码的“ 0”和“+”。而且还需要将电话号码转换为WhatsApp链接。

示例:+971 561545785

输出:

https://wa.me/971561545785 =“ +971”;

$ phone_number =“ 561545785”;

$ newnumber = preg_replace('/^0+?/',',' $ phone_number);

但这只会从中删除零。如何从电话号码中删除0和 + +并保存WhatsApp链接。

The "0" and "+" from the phone number must be removed. And also need to turn the phone number into a WhatsApp link.

Example : +971 561545785

Output : https://wa.me/971561545785

i have tried like this,

$countryCode = "+971";

$phone_number = "561545785";

$newNumber = preg_replace('/^0+?/', 'https://wa.me/'.$countryCode,
$phone_number);

But this only removing the zero from. how can i remove 0 and + from phone number and save a WhatsApp link.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少钕鈤記 2025-02-07 15:27:34

在方括号内使用选项

/^[0+]?/

Use options inside square brackets

/^[0+]?/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文