Make a link

2

How do I check if the link is already correct (eg link ). My application takes the text from a database, and there it can be written like this: "stackoverflow.com".

How do I get the code to know if it already has, and if it does not add to the text?

I'm displaying the link this way, and never forwards correctly if you do not have "https: //"

$row = mysqli_fetch_array($resultado)
echo "<a href=' " . $row['link'] .  " '><span style='padding: 3%'>" . $row['link'] . "</span>";
    
asked by anonymous 21.11.2017 / 04:45

1 answer

0

You can use preg_match() to check if it does not contain the string in the variable and concatenate:

if (!preg_match('/https/', $row['link'])) $row['link'] = "https://".$row['link'];

It would look like this:

$row = mysqli_fetch_array($resultado)
if (!preg_match('/https/', $row['link'])) $row['link'] = "https://".$row['link'];
echo "<a href=' " . $row['link'] .  " '><span style='padding: 3%'>" . $row['link'] . "</span>";
    
21.11.2017 / 05:12