I have a column within my MYSQL database headline TEXT NOT NULL
I would like to go through this column for each of my records and extract the URL if it has one. The URL will be stored in another column article_url VARCHAR (225) NULL
. If there is no URL then it would just put NULL
in the column.
Lastly, I would like this to update each time a new record is inserted into the database. Below is what I have thus far.
UPDATE: here is an example of the headline column of my data
Drastic decline in Social Sciences intake *: http:// bit.ly/2vXzPhQ pic.twitter.com/PAZvG3tX17
as you can see there is a URL in the data set however the URL is broken, all URLs are broken with a space between http:// and the rest of the URL. So I need to get a function in PHP
that can find the Valid or Invalid URL when it gets the Invalid URL it will fix it.
this is what I have thus far.
$result = $conn->query($sql);
$reg_exp = "/^(http(s?): \/\/)?(www\.)+[a-zA-Z0-9\.\-\_]+(\.[a-zA-Z]{2,3})+(\/[a-zA-Z0-9\_\-\s\.\/\?\%\#\&\=]*)?$/";
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc())
{
echo "id: " . $row["id"]. " headline: " . $row["headline"]. "<br>";
if(preg_match($reg_exp, $row["headline"]) == TRUE)
{
echo "URL is valid format";
}
else
{
echo "URL is invalid format";
}
}
}
else
{
echo "0 results";
}