This function is failing to check if there is a url in the text to add a href and so if the user clicks there, redirect it
function url($text)
{
$text=html_entity_decode($text);
$text=" ".$text;
$text=preg_replace('/(http(0,1):\/\/[\w\-\.\/#?&=]*)/','<a href="$1" target="_blank">$1</a>',$text);
return $text;
}
<div class="publi-contenido">
<p><?php echo $posts['contenido']; ?></p>
static function agregar($CodUsua, $contenido, $img,$categoria)
{
$textf=url($contenido);
$con = conexion("root", "");
$consulta = $con->prepare("insert into post(CodPost, CodUsua, contenido, img,categoria) values(null, :CodUsua, :contenido, :img, :categoria)");
$consulta->execute(array(':CodUsua' => $CodUsua,
':contenido' => $textf,
':img' => $img,
':categoria' => $categoria));
}