enlaces tipo phpwiki

From: Date: Fri, 16 Apr 2004 10:52:04 +0000
Subject: enlaces tipo phpwiki
Groups: php.general.es 
Request: Send a blank email to general-es+get-47710@lists.php.net to get a copy of this message
Hola compañerxs: Estoy intentando realizar un interprete html para textos tipo PHPwiki, y cómo no estoy muy puesto en el tema de las expresiones regulares os pido un poco de ayuda. Estoy intentando realizar una interpretación de imágenes y enlaces tipo PHPWiki, aunque he mirado el código de éste me pierdo mucho y no sé concretar donde se hace realmente la interpretación. Lo que quiero conseguir es que al poner, dentro de un texto más o menos largo, un texto tipo [nombre de enlace| http://www.enlace.com/dir/etc...] éste se interprete y que ponga cómo un enlace <a href="http://www.enlace.com...">nombre del enlace</a>. Y que cuando se ponga un texto tipo [...image.png] se interprete y devuelva un texto tipo <img src="...img">... Cómo es común en la lista lo mejor es enviar algo de codigo para que realmente veais que lo estoy intentando, por ahora he probado: $text = eregi_replace("([+)([[:alnum:]#?/&=]+)|([[:alnum:]#?/&=]+)(])", "<A HREF=\"\\2\" TARGET=\"_blank\">\\1</a>", $text); Y he visto que PHPWiki utiliza algo de código del que pego al final, pero no he logrado echarlo a andar y lo veo más complicado... Gracias por ayudarme! UN SALUDO; Rafa function LinkURL($url, $linktext='') { global $ScriptUrl; if(ereg("[<>\"]", $url)) { return "<b><u>BAD URL -- remove all of &lt;, &gt;, &quot;</u></b>"; } if(empty($linktext)) $linktext = htmlspecialchars($url); return "<a href=\"$url\">$linktext</a>"; } function LinkImage($url, $alt='[External Image]') { global $ScriptUrl; if(ereg('[<>"]', $url)) { return "<b><u>BAD URL -- remove all of &lt;, &gt;, &quot;</u></b>"; } return "<img src=\"$url\" ALT=\"$alt\">"; } // strip brackets and leading space preg_match("/(\[\s*)(.+?)(\s*\])/", $bracketlink, $match); // match the contents preg_match("/([^|]+)(\|)?([^|]+)?/", $match[2], $matches); if (isset($matches[3])) { // named link of the form "[some link name | http://blippy.com/]" $URL = trim($matches[3]); $linkname = htmlspecialchars(trim($matches[1]));

« previous php.general.es (#47710) next »