简体   繁体   English

php电话号码中的“0”和“+”怎么去掉

[英]How can remove the "0" and "+" from the phone number in php

The "0" and "+" from the phone number must be removed.必须删除电话号码中的“0”和“+”。 And also need to turn the phone number into a WhatsApp link.并且还需要将电话号码变成WhatsApp链接。

Example: +971 561545785示例:+971 561545785

Output: https://wa.me/971561545785 Output: https://wa.me/971561545785

i have tried like this,我试过这样,

$countryCode = "+971"; $国家代码 = "+971";

$phone_number = "561545785"; $phone_number = "561545785";

$newNumber = preg_replace('/^0+?/', 'https://wa.me/'.$countryCode, $phone_number); $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.如何从电话号码中删除 0 和 + 并保存 WhatsApp 链接。

Use options inside square brackets使用方括号内的选项

/^[0+]?/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM