testando ha fondo ho rivelato un bug utilizzando spazi nella descrizione del link....
Codice PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Link Test</title>
<style type="text/css">
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: normal;
}
#mono {
font-family: monospace;
font-size: 14px;
}
-->
</style>
</head>
<body>
<h1>Link Test</h1>
<?php
function htlm_w3c_url($testo) {
//***********************************************************************************************
// HELP | DA FORM/TXT/DB A TESTO W3C + DECODIFICA URL
//***********************************************************************************************
// trim(); | Rimuove gli spazi (ed altri caratteri) all'inizio e alla fine di un testo
// stripslashes(); | Rimuove gli slash aggiunti con addslashes()
// strip_tags(); | elimina tutti i tag
// htmlentities(); | sostituisce č con è
// nl2br(); | aggiunge
//***********************************************************************************************
$testo = trim($testo);
$testo = strip_tags($testo);
$testo = htmlentities($testo);
$testo = preg_replace( "#\[url\](\S+?)\[/url\]#i" , "<a href=\"\\1\" target=\"_blank\">\\1</a>", $testo );
$testo = preg_replace( "#\[url\s*=\s*\"\;(\S+?)\\s*\"\;\s*\](\S+?)\\[\/url\]#i" , "<a href=\"\\1\" target=\"_blank\">\\2</a>", $testo );
$testo = preg_replace( "#\[url\s*=\s*(\S+?)\\s*\](\S+?)\\[\/url\]#i" , "<a href=\"\\1\" target=\"_blank\">\\2</a>", $testo );
$testo = nl2br($testo);
return $testo;
//...
}
?>
<?php
if ( $_SERVER['REQUEST_METHOD'] == 'POST' && array_key_exists('testo', $_POST) ){
//....
$testo = trim($_POST['testo']);
//....
$testo_url = htlm_w3c_url($testo);
} else {
$testo = NULL;
$testo_url = NULL;
}
//..
if ($testo_url != NULL){
echo "<hr />\n";
echo "[b]Risultato:[/b]
\n";
echo "<div id=\"mono\">\n";
echo $testo_url . "\n";
echo "</div>\n";
echo "<hr />\n";
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
form imput:
<textarea name="testo" cols="80" rows="10"><?= $testo; ?></textarea>
<input name="Invia" type="submit" value="Invia" />
</form>
<hr />
Qui alcuni esempi di link ( Da copiare ed incollare nel form sovrastante per vedere il risultato )
<div id="mono">
1: [URL="http://www.miolink-1.it"]MioLink-1[/URL]
2: [URL="[url]http://www.miolink-2.it"]Mio[/url] Link-2[/URL]
3: [url="http://www.miolink-3.it"]MioLink-3[/url]
4: [URL]http://www.miolink-4.it.com[/URL]
5: [url]http://www.miolink-5.it.com[/url]
</div>
[b]Attenzione:[/b] Il link 2 e errato, l'errore è dovuto dallo spazio Tra Mio e Link-2
come posso utilizzare spazi nella descrizione del link ???.
</body>
</html>
cichity74