如何将数字的字符串值转换为锚标记内的电话格式?

I'm trying to convert a dynamic string value of numbers which might be changed in the future that's why I don't want to hard code it.

<?php $telephone = (03) 1234 5678; // this number displays on the frontend only ?>

<a href="tel:+61-3-1234-5678"><?php echo $telephone; ?></a>

So I want to change/format the value from "(03) 1234 5678" to "tel:+61-3-1234-5678". How can I properly achieve this?

You need to explode your string on the basis of space and after that str_replace to remove (,) and 0 then you find out follow output.this code for php.

    $str="tel:+61-";
    $phone ="(03) 1234 5678";
    $string=explode(" ",$phone);
    $strone=str_replace("(","",$string[0]);
    $strone=str_replace(")","",$strone);
    $strone=str_replace("0","",$strone);
    print_r($str.$strone."-".$string[1]."-".$string[2]);
    exit;