PDA

View Full Version : [php] Sintassi delle espressioni.


ghego
27-10-2005, 21:20
Ciao, mi serve un aiutino :(

Io ho questa funzione,

$text = preg_replace( "`((http)+(s)?:(//)|(www\.))((\w|\.|\-|_)+)(/)?(\S+)?`i", "<a href=\"http\\3://\\5\\6\\8\\9\" title=\"\\0\">\\5\\6</a>", $text);

che cambia in $text se trova un link lo mette in forma html.

Ora il problema č questo dovrei mettere un veto del tipo se prima di http c'č un = non devo effettuare il replace, ora se non ho capito male dovrei usare una cosa tipo [^=] ma se la metto prima cosė:

$text = preg_replace( "`[^=]((http)+(s)?:(//)|(www\.))((\w|\.|\-|_)+)(/)?(\S+)?`i", "<a href=\"http\\3://\\5\\6\\8\\9\" title=\"\\0\">\\5\\6</a>", $text);

praticamente non la mette in azione :(

qualche dritta su come risolvere il problema?

ghego
28-10-2005, 16:07
<?
$stringa = "http://www.test.it <a href=http://www.test.it>a</a>";
$stringa = preg_replace('#[^href=](http://)([^\s]*)#', '<a href="\\1\\2">\\1\\2</a>', $stringa);
echo $stringa;
?>

Ho provato a fare cosė

ma mi omette si di modificare la 2° che non necessita, ma tralascia anche la prima... :(

qualche idea?