Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Community > Tech > [PHP] Espresione regolare
  Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
Napolux
-29 Kg da Settembre 2005

User info:
Registered: Jun 2002
Posts: 3666 (0.42 al dì)
Location: Giussano (MI)
Corso: F28
Anno: ???
Time Online: 21 Days, 19:29:36 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
[PHP] Espresione regolare

Questa è un'espressione che fa il parsing di un URL

PHP:

$string = eregi_replace("(news|http|https|ftp)://([[:alnum:]/\n+-=%&:_.~?]+[#[:alnum:]+]*)","<a href="\1://\2" target="_blank">\1://\2</a>", $string);



Come posso modificarla in modo che non faccia niente se nella stringa, prima del link c'e' una quadra chiusa?

Del tipo "]http://eccetera" ??

Grazie

__________________
Napolux.com

18-01-2005 11:10
Click Here to See the Profile for Napolux Click Here to See the Blog of Napolux Click here to Send Napolux a Private Message Visit Napolux's homepage! Find more posts by Napolux Add Napolux to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Alf
°o.mini sayan.o°

User info:
Registered: Jun 2003
Posts: 5381 (0.65 al dì)
Location: Mediolanum
Corso: Informatica
Anno: FINITOOOO!
Time Online: 155 Days, 9:46:05: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
Re: [PHP] Espresione regolare


Non saprei se puoi mettere una condizione in quella funzione ...


Io metterei semplicemente prima dell'eregi questo:
if(strcmp($string[0],"]")!=0)




Non so se nel tuo caso e' necessario controllare che non sia vuota $string.

__________________
(\ /)
( . .)
c('')('') This is Bunny!
Help her succeed in world domination by copy and pasting her in
your signature.

18-01-2005 11:32
Click Here to See the Profile for Alf Click Here to See the Blog of Alf Click here to Send Alf a Private Message Find more posts by Alf Add Alf to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Napolux
-29 Kg da Settembre 2005

User info:
Registered: Jun 2002
Posts: 3666 (0.42 al dì)
Location: Giussano (MI)
Corso: F28
Anno: ???
Time Online: 21 Days, 19:29:36 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
Re: Re: [PHP] Espresione regolare

Originally posted by Alf
Non saprei se puoi mettere una condizione in quella funzione ...


Io metterei semplicemente prima dell'eregi questo:
if(strcmp($string[0],"]")!=0)



Non so se nel tuo caso e' necessario controllare che non sia vuota $string.


Mah, posso provare ad adatare la tua soluzione ma non è una singola frase che vado a valutare, ma un'intero testo.

Quindi $string[0] non necessariamente farà parte dell'url. Potrebbe anche essere 1000 parole prima.

__________________
Napolux.com

18-01-2005 11:50
Click Here to See the Profile for Napolux Click Here to See the Blog of Napolux Click here to Send Napolux a Private Message Visit Napolux's homepage! Find more posts by Napolux Add Napolux to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DeepBlue
tired guy

User info:
Registered: Sep 2003
Posts: 4258 (0.52 al dì)
Location: CSN
Corso: Info tlc
Anno:
Time Online: 52 Days, 8:40:31 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Io non sono un grandissimo esperto di regex, ma credo che abbia ragione Alf.

Perché non usi due regex? La prima verifica la presenza della parentesi quadra prima di http e la seconda fa tutto il resto.

Qualcosa del tipo:
if (!parentesi_prima_di_http) { fai_eregi_di_blah_blah; }

__________________
~ get Debian! ~ get FreeBSD! ~ get OpenBSD! ~

18-01-2005 12:09
Click Here to See the Profile for DeepBlue Click Here to See the Blog of DeepBlue Click here to Send DeepBlue a Private Message Find more posts by DeepBlue Add DeepBlue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Napolux
-29 Kg da Settembre 2005

User info:
Registered: Jun 2002
Posts: 3666 (0.42 al dì)
Location: Giussano (MI)
Corso: F28
Anno: ???
Time Online: 21 Days, 19:29:36 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

provero'

__________________
Napolux.com

18-01-2005 12:14
Click Here to See the Profile for Napolux Click Here to See the Blog of Napolux Click here to Send Napolux a Private Message Visit Napolux's homepage! Find more posts by Napolux Add Napolux to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Alf
°o.mini sayan.o°

User info:
Registered: Jun 2003
Posts: 5381 (0.65 al dì)
Location: Mediolanum
Corso: Informatica
Anno: FINITOOOO!
Time Online: 155 Days, 9:46:05: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
Re: Re: Re: [PHP] Espresione regolare

Originally posted by Napolux
Mah, posso provare ad adatare la tua soluzione ma non è una singola frase che vado a valutare, ma un'intero testo.

Quindi $string[0] non necessariamente farà parte dell'url. Potrebbe anche essere 1000 parole prima.


Beh adattala l'idea e' quella ... :)
Cerca magari la pos di "http://" e poi controlla che il carattere prima (se c'e') sia diverso da ] :)

Boh guarda tu ... :)

__________________
(\ /)
( . .)
c('')('') This is Bunny!
Help her succeed in world domination by copy and pasting her in
your signature.

18-01-2005 13:11
Click Here to See the Profile for Alf Click Here to See the Blog of Alf Click here to Send Alf a Private Message Find more posts by Alf Add Alf to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
giulio
.no title at all.

User info:
Registered: Jul 2003
Posts: 153 (0.02 al dì)
Location: Earth
Corso: Once upon a time...
Anno:
Time Online: 8 Days, 21:56:12 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
Re: [PHP] Espresione regolare

Originally posted by Napolux
Questa è un'espressione che fa il parsing di un URL
PHP:

$string = eregi_replace("(news|http|https|ftp)://([[:alnum:]/\n+-=%&:_.~?]+[#[:alnum:]+]*)","<a href="\1://\2" target="_blank">\1://\2</a>", $string);



Come posso modificarla in modo che non faccia niente se nella stringa, prima del link c'e' una quadra chiusa?

Del tipo "]http://eccetera" ??

Grazie


Aggiungi [^]] all'inizio dell'espressione regolare:

$string = eregi_replace("[^]](news|http|https|ftp)://([[:alnum:]/\n+-=%&:_.~?]+[#[:alnum:]+]*)","<a href=\"\1://\2\" target=\"_blank\">\1://\2</a>", $string);
Attenzione che non funziona (cioe' niente replace) nel caso l'URL sia all'inizio
di $string.

Ciao,
gc

18-01-2005 13:46
Click Here to See the Profile for giulio Click here to Send giulio a Private Message Find more posts by giulio Add giulio to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Napolux
-29 Kg da Settembre 2005

User info:
Registered: Jun 2002
Posts: 3666 (0.42 al dì)
Location: Giussano (MI)
Corso: F28
Anno: ???
Time Online: 21 Days, 19:29:36 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

l'avevo gia' provato.

fatto, per le immagini funziona, ma per gli url non fa più il parsing :(

__________________
Napolux.com

18-01-2005 13:47
Click Here to See the Profile for Napolux Click Here to See the Blog of Napolux Click here to Send Napolux a Private Message Visit Napolux's homepage! Find more posts by Napolux Add Napolux to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Napolux
-29 Kg da Settembre 2005

User info:
Registered: Jun 2002
Posts: 3666 (0.42 al dì)
Location: Giussano (MI)
Corso: F28
Anno: ???
Time Online: 21 Days, 19:29:36 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Forse ho trovato, ci lavoro questo pomeriggio e poi vi faccio sapere :D

__________________
Napolux.com

18-01-2005 13:53
Click Here to See the Profile for Napolux Click Here to See the Blog of Napolux Click here to Send Napolux a Private Message Visit Napolux's homepage! Find more posts by Napolux Add Napolux to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Napolux
-29 Kg da Settembre 2005

User info:
Registered: Jun 2002
Posts: 3666 (0.42 al dì)
Location: Giussano (MI)
Corso: F28
Anno: ???
Time Online: 21 Days, 19:29:36 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Risolto con i token....

__________________
Napolux.com

19-01-2005 18:29
Click Here to See the Profile for Napolux Click Here to See the Blog of Napolux Click here to Send Napolux a Private Message Visit Napolux's homepage! Find more posts by Napolux Add Napolux to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 23:22.    Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

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
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.059 seconds (71.55% PHP - 28.45% MySQL) con 23 query.