Link

Asked

Viewed 50 times

2

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

How to make the code know if it already has, and if it doesn’t have to add to the text?

I am displaying the link this way, and never forwards right if you are not with "https://"

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

1 answer

0

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

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

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>";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.