I have developed a nice little FAQ for my site. Everything is stored in a MySQL database from Category, Question and Answer, the collumns is VARCHAR (255). I use the following code before adding anything I input to the database and only I have access to what gets added, edited or deleted.
htmlspecialchars($_POST['xxxxxx'])
What is the best way to get the data from the database and echo it out as clickable URL’s using PHP? Most of the information I have found seems to be 10 – 12 years old and many functions are now deprecated. I am not so sure security would not be an issue as it does not allow user input unless it is from myself. I know this question has been asked many times but I only find outdated code.
>Solution :
This solution will catch all http/https/www and convert to clickable links.
Convert plain text URLs into HTML hyperlinks in PHP
$url = ‘/(http|https|ftp|ftps)://[a-zA-Z0-9-.]+.[a-zA-Z]{2,3}(/\S*)?/’;
$string= preg_replace($url, ‘$0’, $string);
echo $string;