Convertir enlaces de texto a enlaces HTML con PHP

  • Autor Autor Wext
  • Fecha de inicio Fecha de inicio
W

Wext

Beta
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Bueno es simple tengo el siguiente code 😀

Este es el index.html
HTML:
<form action='procesar.php' method='post'>
Ingrese su nombre:<br>
<input type='text' name='nombre'>
<br>
Comentarios:
<br>
<textarea name='comentarios' rows='10' cols='40'>
</textarea>
<br>
<input type='submit' value='Registrar'>
</form>

y el php
PHP:
<?php
$prefijo = substr(md5(uniqid(rand())),0,6);
$contenido="$_POST[comentarios]";
$fp=fopen("database/".$prefijo."_".$_POST["nombre"].".html","x");
fwrite($fp,$contenido);
fclose($fp) ;


echo "<center>Compartelo:<br>";
echo "Nombre del archivo:<span style='color:#fc0000;'> ".$prefijo."_".$_POST["nombre"]."</span><br>";
echo "Previsualiza el contenido: <br><iframe src='database/".$prefijo."_".$_POST["nombre"].".html' frameborder='0'></iframe><br>";
echo "</center>";
?>

Lo que quiero hacer es que cuando en el textarea del index.html se ponga un enlace en el code php lo interprete como tal y el enlace quede como un enlace jaja valgame la irreverencia, osea se pone un enlace y se guarda como texto normal, lo que quiero es que tenga un link ese texto 😀 si necesitan mas especificaciones me dicen 😀 gracias de antemano que tengan un bonito día.
 
Última edición:
Con preg_replace y algo de Regex 😀

PHP:
<?php
$texto = "hola soy jp y estoy en http://forobeta.com/ :|";
$texto = preg_replace('/(https{0,1}:\/\/[\w\-\.\/#?&=]*)/', '<a href="$1" target="_blank">$1</a>', $texto);

echo $texto;
 
Con preg_replace y algo de Regex 😀

PHP:
<?php
$texto = "hola soy jp y estoy en http://forobeta.com/ :|";
$texto = preg_replace('/(https{0,1}:\/\/[\w\-\.\/#?&=]*)/', '<a href="$1" target="_blank">$1</a>', $texto);

echo $texto;

:O ya lo puse pero es q no me da D: me ayudarías a acomodarlo en mi code?
 
PHP:
function makeClickableLinks($text)
{

        $text = html_entity_decode($text);
        $text = " ".$text;
        $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
                '<a href="\\1" target=_blank>\\1</a>', $text);
        $text = eregi_replace('(((f|ht){1}tps://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
                '<a href="\\1" target=_blank>\\1</a>', $text);
        $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
        '\\1<a href="http://\\2" target=_blank>\\2</a>', $text);
        $text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
        '<a href="mailto:\\1" target=_blank>\\1</a>', $text);
        return $text;
}

Enlace eliminado

google... y google... y google...

Enlace eliminado
 
PHP:
function makeClickableLinks($text)
{

        $text = html_entity_decode($text);
        $text = " ".$text;
        $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
                '<a href="\\1" target=_blank>\\1</a>', $text);
        $text = eregi_replace('(((f|ht){1}tps://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
                '<a href="\\1" target=_blank>\\1</a>', $text);
        $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
        '\\1<a rel="nofollow" href="http://\\2" target=_blank>\\2</a>', $text);
        $text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
        '<a href="mailto:\\1" target=_blank>\\1</a>', $text);
        return $text;
}

Enlace eliminado

google... y google... y google...

Enlace eliminado

Si yo tabn encontré eso pero es que no c integrarlo al code mio y es lo q necesito
 
PHP:
<?php
function makeClickableLinks($text)
{

        $text = html_entity_decode($text);
        $text = " ".$text;
        $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
                '<a href="\\1" target=_blank>\\1</a>', $text);
        $text = eregi_replace('(((f|ht){1}tps://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
                '<a href="\\1" target=_blank>\\1</a>', $text);
        $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
        '\\1<a href="http://\\2" target=_blank>\\2</a>', $text);
        $text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
        '<a href="mailto:\\1" target=_blank>\\1</a>', $text);
        return $text;
}

$prefijo = substr(md5(uniqid(rand())),0,6);
$contenido=makeClickableLinks($_POST[comentarios]);
$fp=fopen("database/".$prefijo."_".$_POST["nombre"].".html","x");
fwrite($fp,$contenido);
fclose($fp) ;

echo "<center>Compartelo:<br>";
echo "Nombre del archivo:<span style='color:#fc0000;'> ".$prefijo."_".$_POST["nombre"]."</span><br>";
echo "Previsualiza el contenido: <br><iframe src='database/".$prefijo."_".$_POST["nombre"].".html' frameborder='0'></iframe><br>";
echo "</center>";
?>
 
Yo si soy de lo mas animal :facepalm: jajajajaja tengan mucha paciencia con migo q soy como medio lento... jajaj
 

Temas similares

Atrás
Arriba