PHP 7 Script to Convert URLs Within Text String into Clickable Links in Browser Full Project For Beginners

  • Post author:
  • Post category:PHP
  • Post comments:0 Comments

 

Welcome folks today in this blog post we will be converting urls within text string into clickable links in browser using php 7. All the full source code of the application is shown below.

 

 

 

Get Started

 

 

 

In order to get started you need to make an index.php file and copy paste the following code

 

 

index.php

 

 

<?php
$str = "https://codespeedy.com is an amazing website where you can find tutorials on various types of programming languages. Visit https://codespeedy.com regularly.";
$url_pattern = '/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/';   
$str= preg_replace($url_pattern, '<a href="$0">$0</a>', $str);
echo $str;
?>

Leave a Reply