note 42448 deleted from function.preg-replace by nlopess

From: Date: Mon, 17 May 2004 13:11:59 +0000
Subject: note 42448 deleted from function.preg-replace by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-69714@lists.php.net to get a copy of this message
Note Submitter: interiority-doot-com ---- What an amateur I am. I pasted the wrong code into my note, this is the good one (sorry for the break-ups, the lines were too long): if ( preg_match( "/(http|ftp)+(s)?:(\/\/)((\w|\.|\-|_)+)(\/)?(\S+)?/i", $theText)) { $theText = preg_replace( "/(http|ftp)+(s)?:(\/\/)((\w|\.|\-|_)+)(\/)?(\S+)?/i", "<a href=\"$0\" target=\"_blank\">$4</a>", $theText); } else if ( preg_match( "/(www(.[\w]+))((\w|\.|\-|_)+)(\/)?(\S+)?/i", $theText) ) { $theText = preg_replace( "/(www(.[\w]+))((\w|\.|\-|_)+)(\/)?(\S+)?/i", "<a href=\"http://$0\" target=\"_blank\">$1$3</a>", $theText); }#endif If you need to replace several URL's inside the same function (the one above only replaces one instance of a URL), then you can use this one: $theText = preg_replace( "/[http|ftp+s?:\/\/]*(www(.[\w]+)) ((\w|\.|\-|_)+)(\/)?(\S+)?/i", "<a href=\"http://$1$3$5$6\" target=\"_blank\"> $1$3</a>", $theText );

« previous php.notes (#69714) next »