|
|
|
|
 |
|  |
 |
^Angelus^ |
| [PHP & RegEx] Aiutooo!!! |
18-11-2004 17:56 |
|
 |
^Angelus^ |
.illuminato.

Registered: Sep 2002
Posts: 163 (0.02 al dì)
Location: nelle vicinanze di Comelico beach
Corso: Informatica (ex Com Dig)
Anno: Bella domanda
Time Online: 3 Days, 21:34:49 [...]
Status: Offline
Edit | Report | IP: Logged |
[PHP & RegEx] Aiutooo!!!
Sto cercando di fare in php un sistema per inserire dei contenuti in un sito simile a quella di questo forum ma non me la cavo molto con le espressioni regolari. Per i tag tipo il bold non ci sono troppi problemi, il problema l'ho trovato per i link. Qualcuno saprebbe farmi l'espressione per sostituire nel testo i link e l'email messi tipo come li mette questo forum nei rispettivi tag html?
PHP:
[LINK=http://www.sito.com]sito[/LINK]
[LINK]http://www.miosito.com[/LINK]
per i link
email
mail@mail.com
per l'email
grazie in anticipo
__________________
Empty your mind, be formless, shapeless, like water. If you put water into a cup it became a cup, if you put water into a bottle it became a bottle, if you put into a teapot it became a teapot. Water can flow or can crush. Be water my friend.
Nessuna via come via. Nessun limite come limite
- Bruce Lee -
|
|
18-11-2004 17:56 |
|
|
|  |
 |
ripe |
| Non trovi nulla di già pronto?
... |
18-11-2004 18:32 |
|
 |
ripe |
- up in the mountains -

Registered: Jun 2002
Posts: 9469 (1.10 al dì)
Location: Cinisellooo
Corso: TICO TICO
Anno: Primo
Time Online: 61 Days, 2:33:39 [...]
Status: Offline
Edit | Report | IP: Logged |
Non trovi nulla di già pronto?
http://www.regexlib.com/
__________________
«And if you ever smell christian blood up in the mountains, then get your axe and chop them down!»
|
|
18-11-2004 18:32 |
|
|
|  |
 |
ripe |
| E soprattutto, non puoi realizzare la stessa cosa ... |
18-11-2004 18:32 |
|
 |
ripe |
- up in the mountains -

Registered: Jun 2002
Posts: 9469 (1.10 al dì)
Location: Cinisellooo
Corso: TICO TICO
Anno: Primo
Time Online: 61 Days, 2:33:39 [...]
Status: Offline
Edit | Report | IP: Logged |
E soprattutto, non puoi realizzare la stessa cosa con un mini-parserino? Mi sembra una fatica inutile la regular expression (anche se più pulita)...
__________________
«And if you ever smell christian blood up in the mountains, then get your axe and chop them down!»
|
|
18-11-2004 18:32 |
|
|
|  |
 |
JaM |
| questo e' quello che ho messo nel guestbook del mi ... |
18-11-2004 19:47 |
|
 |
JaM |
######

Registered: Jun 2002
Posts: 3604 (0.42 al dì)
Location: everywhere, anywhere, elsewhere...
Corso: ComDig
Anno: dott.??
Time Online: 62 Days, 16:55:46 [...]
Status: Offline
Edit | Report | IP: Logged |
questo e' quello che ho messo nel guestbook del mio sito
PHP:
<?
//$final e' la stringa di testo
//search for tag [url]
if (eregi("[url", $final ))
{
$final = eregi_replace("[url="http://", "<a target="_blank" href="http://", $final);
$final = eregi_replace("[url="", "<a target="_blank" href="http://", $final);
$final = eregi_replace(""]", "">", $final);
$final = eregi_replace("[/url]", "</a>", $final);
}
//search for tag [img]
if (eregi("[img]", $final ))
{
$final = eregi_replace("[img]http://", "<img src="http://", $final);
$final = eregi_replace("[img]", "<img src="http://", $final);
$final = eregi_replace("[/img]", "">", $final);
}
//activate urls
$final = html_activate_urls($final);
//correct some bugs of the [url] tag
$final = eregi_replace("[url]", "", $final);
$final = str_replace("</a></a>", "</a>", $final);
//print final text
if ($final=="") $final=$nothing;
echo strip_tags($final,"<a><img><div><b><i><u><br>")."<br><div align="center">";
//Thanks to "Krzysiek Kobrzak" and "hdn" from <a href="http://www.php.net" target="_blank">www.php.net</a> manual comments for their url2links functions that I used here with some modifications
function html_activate_urls($str)
{
// lift all links and images
preg_match_all("/<a [^>]+>.*</a>/is", $str, $matches, PREG_SET_ORDER);
foreach($matches as $match)
{
$key = "<" . md5($match[0]) . ">";
$search[] = $key;
$replace[] = $match[0];
}
preg_match_all("/<img [^>]+>/is", $str, $matches, PREG_SET_ORDER);
foreach($matches as $match)
{
$key = "<" . md5($match[0]) . ">";
$search[] = $key;
$replace[] = $match[0];
}
//The URL must start with "http:// (ftp, https)", "http://www" or just "www".
if (!isset($replace)) $replace="";
if (!isset($search)) $search="";
$str = str_replace($replace, $search, $str);
$str = eregi_replace ("[[:alpha:]]+://www", "www",$str);
$str = ereg_replace ("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/](.[a-z0-9-]{2,4})+", "<a class="linkneltesto" href="\0" target="_blank">\0</a>", $str);
$str = ereg_replace ("www.[^<>[:space:]]+[[:alnum:]/](.[a-z0-9-]{2,4})+", "<a class="linkneltesto" href="http://\0" target="_blank">\0</a>", $str);
return str_replace($search, $replace, $str);
}
?>
spero di non aver tralasciato qualche pezzo importante... ho dovuto fare un po' di copia e incolla
la parte delle mail la avevo eliminata nella funzione html_activate_urls ma se cerci nei mauali online di php.net la ritrovi completa di parser per le mail
ps: il guestbook completo lo puoi scaricare qua http://jam.altervista.org/guestbook.zip
|
|
18-11-2004 19:47 |
|
|
|  |
 |
^Angelus^ |
| Grazie mille... oggi provo ad implementarlo...le e ... |
19-11-2004 09:04 |
|
 |
^Angelus^ |
.illuminato.

Registered: Sep 2002
Posts: 163 (0.02 al dì)
Location: nelle vicinanze di Comelico beach
Corso: Informatica (ex Com Dig)
Anno: Bella domanda
Time Online: 3 Days, 21:34:49 [...]
Status: Offline
Edit | Report | IP: Logged |
Grazie mille... oggi provo ad implementarlo...le espressioni regolari proprio non riesco a diggerirle
__________________
Empty your mind, be formless, shapeless, like water. If you put water into a cup it became a cup, if you put water into a bottle it became a bottle, if you put into a teapot it became a teapot. Water can flow or can crush. Be water my friend.
Nessuna via come via. Nessun limite come limite
- Bruce Lee -
|
|
19-11-2004 09:04 |
|
|
|  |
 |
^Angelus^ |
| Non funziona :sad:
... |
19-11-2004 11:13 |
|
 |
^Angelus^ |
.illuminato.

Registered: Sep 2002
Posts: 163 (0.02 al dì)
Location: nelle vicinanze di Comelico beach
Corso: Informatica (ex Com Dig)
Anno: Bella domanda
Time Online: 3 Days, 21:34:49 [...]
Status: Offline
Edit | Report | IP: Logged |
Non funziona
Ho stampato la stringa iniziale e quella finale, e non va bene per niente.... in + mi da pure dei warning che non capisco e su php.net non dice niente a proposito.... ho cercato per vari forum e pare che lo dia per pattern sbagliati. Da quel poco che so di espressioni regolari, mi pare che tu usi le quadre in modo errato, in quanto sono dei caratteri riservati. Cmq ecco quello che mi viene fuori
Stringa iniziale
http://www.yahoo.it blal bala blalkaj http://www.cicciociccio.it [TAGURL]www.pippo.it[/TAGURL]
Warning: eregi(): REG_EBRACK in /var/www/vhosts/xxxxxxxx/xxxxxxx.it/httpdocs/test/regex.php on line 6
Warning: Unknown modifier 'a' in /var/www/vhosts/xxxxxxxx/xxxxxxxx.it/httpdocs/test/regex.php on line 35
Stringa finale
http:">">"> sc="http:">">t ba baa bakaj http:">">www.c">"> sc="http:">">cc">"> sc="http:">">oc">"> sc="http:">">cc">"> sc="http:">">o.">"> sc="http:">">t []www.p">"> sc="http:">">ppo.">"> sc="http:">">t[">]
Ho messo TAGURL perchè se no il forum me lo convertiva in link
__________________
Empty your mind, be formless, shapeless, like water. If you put water into a cup it became a cup, if you put water into a bottle it became a bottle, if you put into a teapot it became a teapot. Water can flow or can crush. Be water my friend.
Nessuna via come via. Nessun limite come limite
- Bruce Lee -
Last edited by ^Angelus^ on 19-11-2004 at 11:19
|
|
19-11-2004 11:13 |
|
|
|  |
 |
JaM |
| nel mio blog funziona.... e ho copiato il codice d ... |
19-11-2004 13:35 |
|
 |
JaM |
######

Registered: Jun 2002
Posts: 3604 (0.42 al dì)
Location: everywhere, anywhere, elsewhere...
Corso: ComDig
Anno: dott.??
Time Online: 62 Days, 16:55:46 [...]
Status: Offline
Edit | Report | IP: Logged |
nel mio blog funziona.... e ho copiato il codice dalla pagina che c'e' online..... 
|
|
19-11-2004 13:35 |
|
|
|  |
 |
^Angelus^ |
| Risolto....ho penato un po' però. Ho utilizzato u ... |
21-11-2004 20:56 |
|
 |
^Angelus^ |
.illuminato.

Registered: Sep 2002
Posts: 163 (0.02 al dì)
Location: nelle vicinanze di Comelico beach
Corso: Informatica (ex Com Dig)
Anno: Bella domanda
Time Online: 3 Days, 21:34:49 [...]
Status: Offline
Edit | Report | IP: Logged |
Risolto....ho penato un po' però. Ho utilizzato un altra funzione, la preg_replace con degli aggiustamenti ai pattern e rifacendone buona parte. Devo dire che finalmente ho imparato a usare i RegEx, e mi chiedo come fanno a funzionare sul tuo blog... perchè alcuni pattern sono palesemente errati, faccio un esempio:
"[url=\"http://"
il carattere [ è un carattere utilizzato per la sintassi delle regex, in questo caso di dovrebbe indicare così \[, così mi sembra veramente strano che funzioni...boh boh
__________________
Empty your mind, be formless, shapeless, like water. If you put water into a cup it became a cup, if you put water into a bottle it became a bottle, if you put into a teapot it became a teapot. Water can flow or can crush. Be water my friend.
Nessuna via come via. Nessun limite come limite
- Bruce Lee -
|
|
21-11-2004 20:56 |
|
|
|  |
 |
JaM |
| mah.... funziona.... :asd: ... |
21-11-2004 22:14 |
|
 |
JaM |
######

Registered: Jun 2002
Posts: 3604 (0.42 al dì)
Location: everywhere, anywhere, elsewhere...
Corso: ComDig
Anno: dott.??
Time Online: 62 Days, 16:55:46 [...]
Status: Offline
Edit | Report | IP: Logged |
mah.... funziona.... 
|
|
21-11-2004 22:14 |
|
|
|  |
 |
| All times are GMT. The time now is 20:23. |
|
|
 |
|
 |
|
|
|  |
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
|
|
|
|
|
|