Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Replace Number into tell tag using PHP

How can I convert all numbers into the tel: tag.

For Example:

$string = "Hi this is my number with country code +923416902120. And this is my number without country code 03416902120";

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I want the number to convert into a <a href="tel:+923416902120">+923416902120</a> like this.

$string = "Hi this is my number with country code <a href="tel:+923416902120">+923416902120</a>. And this is my number without country code <a href="tel:03416902120">03416902120</a>";

How can I do this?

>Solution :

Using preg_replace we can try:

$string = "Hi this is my number with country code +923416902120. And this is my number without country code 03416902120";
$output = preg_replace("/\+?\d{6,}/", "<a href=\"tel:$0\">$0</a>", $string);
echo $output;

This prints:

Hi this is my number with country code +923416902120. And this is my number without country code 03416902120

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading