PDA

View Full Version : [PHP] ereg


max246
15-06-2008, 10:34
non riesco a ricavare da questa stringa :

window.location='http://cinema.ti-cket.ch/aa_ticket_new/film.asp?programma=848&film=386&cinema=2&ora=1';" onmouseout="this.style.backgroundColor='';this.style.color='#565656'">

solamente l'url che gli passa come window.location... avete qualche consiglio?

Io sono riuscito ad arrivare fino qua eregi("window.location='(.+)",$forum,$dati);

kk3z
15-06-2008, 11:39
Ti sei dimenticato la virgoletta che chiude l'url, ma in ogni caso non funziona, l'operatore +, essendo greedy, prenderà tutto il testo fino all'ultima virgoletta '. Prova con
eregi("window.location='([^']+)'",$forum,$dati);

Cioè prende tutti i caratteri fino a quando non incontra una virgoletta (^')

max246
15-06-2008, 12:30
Ok funziona :D
però c'è ancora un piccolo problema... mi prende solo i primi due location che trova e non tutti...

Il risultato è Array ( [0] => window.location='http://cinema.ti-cket.ch/aa_ticket_new/film.asp?programma=848&film=386&cinema=2&ora=1' [1] => http://cinema.ti-cket.ch/aa_ticket_new/film.asp?programma=848&film=386&cinema=2&ora=1 )

Pero nell'html passato c'è :
<tr onmouseover="this.style.backgroundColor='#565656';this.style.cursor='hand';this.style.color='#ffffff'" onclick="window.location='http://cinema.ti-cket.ch/aa_ticket_new/film.asp?programma=848&film=386&cinema=2&ora=1';" onmouseout="this.style.backgroundColor='';this.style.color='#565656'">
<td valign=top>IL CACCIATORI DI AQUILONI</td>

</tr>
<tr>
<td valign=top bgcolor="#E4E4E4"><img src="/img/trasp.gif" width="1" height="1" alt=""></td>
</tr>

<tr onmouseover="this.style.backgroundColor='#565656';this.style.cursor='hand';this.style.color='#ffffff'" onclick="window.location='http://cinema.ti-cket.ch/aa_ticket_new/film.asp?programma=848&film=446&cinema=2&ora=2';" onmouseout="this.style.backgroundColor='';this.style.color='#565656'">
<td valign=top>FEEL THE NOISE</td>
</tr>
<tr>
<td valign=top bgcolor="#E4E4E4"><img src="/img/trasp.gif" width="1" height="1" alt=""></td>

</tr>

<tr onmouseover="this.style.backgroundColor='#565656';this.style.cursor='hand';this.style.color='#ffffff'" onclick="window.location='http://cinema.ti-cket.ch/aa_ticket_new/film.asp?programma=848&film=420&cinema=2&ora=3';" onmouseout="this.style.backgroundColor='';this.style.color='#565656'">
<td valign=top>INDIANA JONES E IL REGNO DEL TESCHIO DI CRISTALLO</td>
</tr>
<tr>
<td valign=top bgcolor="#E4E4E4"><img src="/img/trasp.gif" width="1" height="1" alt=""></td>
</tr>

<tr onmouseover="this.style.backgroundColor='#565656';this.style.cursor='hand';this.style.color='#ffffff'" onclick="window.location='http://cinema.ti-cket.ch/aa_ticket_new/film.asp?programma=848&film=439&cinema=2&ora=4';" onmouseout="this.style.backgroundColor='';this.style.color='#565656'">
<td valign=top>UN AMORE DI TESTIMONE</td>

</tr>
<tr>
<td valign=top bgcolor="#E4E4E4"><img src="/img/trasp.gif" width="1" height="1" alt=""></td>
</tr>

<tr onmouseover="this.style.backgroundColor='#565656';this.style.cursor='hand';this.style.color='#ffffff'" onclick="window.location='http://cinema.ti-cket.ch/aa_ticket_new/film.asp?programma=848&film=374&cinema=2&ora=5';" onmouseout="this.style.backgroundColor='';this.style.color='#565656'">
<td valign=top>SOGNI E DELITTI</td>
</tr>
<tr>
<td valign=top bgcolor="#E4E4E4"><img src="/img/trasp.gif" width="1" height="1" alt=""></td>

</tr>

<tr onmouseover="this.style.backgroundColor='#565656';this.style.cursor='hand';this.style.color='#ffffff'" onclick="window.location='http://cinema.ti-cket.ch/aa_ticket_new/film.asp?programma=848&film=448&cinema=2&ora=6';" onmouseout="this.style.backgroundColor='';this.style.color='#565656'">
<td valign=top>L'INCREDIBILE HULK</td>
</tr>

max246
16-06-2008, 08:14
up qualcuno sa aiutarmi? :(

kk3z
16-06-2008, 10:20
ereg ritorna non appena trova un match, prova con preg_match_all:
preg_match_all("#window.location='([^']+)'#i", $forum, $dati);

PS: non ritorna solo due location, il primo è il match completo, il secondo è quello che hai richiesto tra parentesi

max246
17-06-2008, 19:54
Devo rompere ancora una volta :)

<div style="margin-bottom:5px; padding:0;">
<p style="font-weight:bold; float:left; margin:0; padding:0; width:50%; clear:both;">Bernina</p>
<stato>
Aperto</p>
</stato><ora>17 giugno 2008 - 20.42</p>
</div>


Questo html devo ricavare la parola "Aperto" ma riesco a creare una espressione che prende i dati dentro a un NEW LINE e dei tabulatori. Perchè tra <stato> e Aperto ci sono tabulatori e una nuova linea....

Qualcuno sa aiutarmi? :)

max246
18-06-2008, 08:00
UP :(

max246
18-06-2008, 11:52
UPPP

max246
18-06-2008, 13:37
up

kk3z
19-06-2008, 11:04
prova con
preg_match_all("#<stato>(.+?)</stato>#mis", $testo, $matches);

kk3z
19-06-2008, 16:52
mi spieghi perchè ora mi dici di mettere #mis come finale e nell'altro esempio mi metti solo #i?

http://it.php.net/pcre.pattern.modifiers

in realtà avrei potuto usare solo "is" ma per comodità specifico tutti i modifier insieme (non si sa mai che qualche volta possono servire).

In questo caso, nel primo esempio di "s" non ce n'era bisogno, nel secondo sì, essendo il contenuto del tag <stato> su più righe.