M.b.v. preg_match deel uit javascript gedeelte HTML pagina halen
Een deel van de source waar ik de informatie uit wil halen, lk_fbot0.htm: (In praktijk is PageArray[0] veel langer)
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
var htmlfile="";
var lettertype = "Arial";
var PageArray = new CreateArray(4);
PageArray[0]="abcdefghijklm<BR> <center><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"z\"><tr><td class=y>1</td><td class=y>2</td><td class=y>doc.</td><td class=y>3</td><td class=y>4</td><td class=y>5</td><td class=y>doc.</td><td class=y>6</td></tr></table></center><center><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"z\"><tr><td class=x>a</td><td class=x>6</td><td class=x>b</td><td class=x>c</td><td class=x>d</td></tr></table>";
PageArray[1]="Net zo iets als PageArray[0]";
var SecTeller=0
var wtime = null;
var lettertype = "Arial";
var PageArray = new CreateArray(4);
PageArray[0]="abcdefghijklm<BR> <center><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"z\"><tr><td class=y>1</td><td class=y>2</td><td class=y>doc.</td><td class=y>3</td><td class=y>4</td><td class=y>5</td><td class=y>doc.</td><td class=y>6</td></tr></table></center><center><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"z\"><tr><td class=x>a</td><td class=x>6</td><td class=x>b</td><td class=x>c</td><td class=x>d</td></tr></table>";
PageArray[1]="Net zo iets als PageArray[0]";
var SecTeller=0
var wtime = null;
Tot nu toe heb ik het volgende:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
<?php
$ch = curl_init("http://192.168.0.3/lk_fbot0.htm");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$content = curl_exec($ch);
curl_close($ch);
preg_match ("|PageArray\[1\]=\"([a-z 0-9]{1,10000})\";|i", $content, $out);
echo $out[1];
?>
$ch = curl_init("http://192.168.0.3/lk_fbot0.htm");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$content = curl_exec($ch);
curl_close($ch);
preg_match ("|PageArray\[1\]=\"([a-z 0-9]{1,10000})\";|i", $content, $out);
echo $out[1];
?>
Als ik de HTML tekens ook toevoeg aan de [a-z 0-9] lijst, dan voldoen ook alle andere regels aan de eis, en komt er uiteindelijk dus een error omdat $out[1] niet bestaat. Hoe kan ik alsnog de informatie van PageArray[0] krijgen?
(In het voorbeeld bevindt het bestand lk_fbot0.htm zich op mijn server: in de praktijk is het een externe webpagina, waar ik niets aan kan veranderen)
Gewijzigd op 09/09/2012 18:37:11 door Patrick S
Gewijzigd op 14/09/2012 22:43:58 door Patrick S
wat krijg je nu? en wat wil je precies hebben uit het js gedeelte?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="style.css" type="text/css">
<TITLE>webpage</TITLE>
<SCRIPT LANGUAGE="JavaScript">
var ns4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;
var d = parent.output.document,t = parent.topframe.document;
var HTMLMaxtijd=0;
var Maxtijd=15;
var PagesBeforeUpdate=21;
var MainPages = 3;
var NrOfPages = 3;
var MaxNrOfPeriodes = -1;
var Uitschakeltijd = "99:99";
var htmlfile="";
var lettertype = "Arial";
var PageArray = new CreateArray(3);
PageArray[0]="blabla tekst<BR> <BR>";
PageArray[1]="14-09<BR>ikben: ABC<BR><center><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"z\"><tr><td class=x>klas</td><td class=x>uur</td><td class=x>docent</td><td class=x>vak</td><td class=x>lokaal</td><td class=x>vak</td><td class=x>docent</td><td class=x>lokaal</td></tr></table></center><center><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"z\"><tr><td class=y>1C</td><td class=y>4</td><td class=y>LAT</td><td class=y>ne</td><td class=y>101</td><td class=y>ne</td><td class=y>LAT</td><td class=y>117</td></tr><tr><td class=x>1G</td><td class=x>4</td><td class=x>ROW</td><td class=x>en</td><td class=x>015</td><td class=x>en</td><td class=x>VEM</td><td class=x>015</td></tr><tr><td class=y>2M</td><td class=y>6</td><td class=y>SCL</td><td class=y>en</td><td class=y>015</td><td class=y>en</td><td class=y>SCL</td><td class=y>010</td></tr></table></center> <BR> <BR>";
PageArray[2]="17-09<BR>hallo (7-7)<BR><center><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"z\"><tr><td class=x>klas</td><td class=x>uur</td><td class=x>docent</td><td class=x>vak</td><td class=x>lokaal</td><td class=x>docent</td><td class=x>vak</td></tr></table></center><center><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"z\"><tr><td class=y>1F</td><td class=y>4</td><td class=y>BUF</td><td class=y>M</td><td class=y>238</td><td class=y>BUF</td><td class=y>M</td></tr><tr><td class=x>1G</td><td class=x>3</td><td class=x>BOY</td><td class=x>ne</td><td class=x>157</td><td class=x>BOY</td><td class=x>ne</td></tr><tr><td class=y>2M</td><td class=y>6</td><td class=y>DIM</td><td class=y>M</td><td class=y>106</td><td class=y>MAA</td><td class=y>ak</td></tr><tr><td class=x>5V1, 5V3,</td><td class=x>5</td><td class=x>DIM</td><td class=x>ak6</td><td class=x>106</td><td class=x>BRE</td><td class=x>ak6</td></tr><tr><td class=y>5V1</td><td class=y>2</td><td class=y>SLR</td><td class=y>na2</td><td class=y>205</td><td class=y>HUP</td><td class=y>na2</td></tr></table></center> <BR>";
var SecTeller=0
var wtime = null;
var width,margin;
var tgs = new Array( "div","td","th","pre");
var PageTeller=0;
</SCRIPT>
</body></html>
<link rel="stylesheet" href="style.css" type="text/css">
<TITLE>webpage</TITLE>
<SCRIPT LANGUAGE="JavaScript">
var ns4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;
var d = parent.output.document,t = parent.topframe.document;
var HTMLMaxtijd=0;
var Maxtijd=15;
var PagesBeforeUpdate=21;
var MainPages = 3;
var NrOfPages = 3;
var MaxNrOfPeriodes = -1;
var Uitschakeltijd = "99:99";
var htmlfile="";
var lettertype = "Arial";
var PageArray = new CreateArray(3);
PageArray[0]="blabla tekst<BR> <BR>";
PageArray[1]="14-09<BR>ikben: ABC<BR><center><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"z\"><tr><td class=x>klas</td><td class=x>uur</td><td class=x>docent</td><td class=x>vak</td><td class=x>lokaal</td><td class=x>vak</td><td class=x>docent</td><td class=x>lokaal</td></tr></table></center><center><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"z\"><tr><td class=y>1C</td><td class=y>4</td><td class=y>LAT</td><td class=y>ne</td><td class=y>101</td><td class=y>ne</td><td class=y>LAT</td><td class=y>117</td></tr><tr><td class=x>1G</td><td class=x>4</td><td class=x>ROW</td><td class=x>en</td><td class=x>015</td><td class=x>en</td><td class=x>VEM</td><td class=x>015</td></tr><tr><td class=y>2M</td><td class=y>6</td><td class=y>SCL</td><td class=y>en</td><td class=y>015</td><td class=y>en</td><td class=y>SCL</td><td class=y>010</td></tr></table></center> <BR> <BR>";
PageArray[2]="17-09<BR>hallo (7-7)<BR><center><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"z\"><tr><td class=x>klas</td><td class=x>uur</td><td class=x>docent</td><td class=x>vak</td><td class=x>lokaal</td><td class=x>docent</td><td class=x>vak</td></tr></table></center><center><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"z\"><tr><td class=y>1F</td><td class=y>4</td><td class=y>BUF</td><td class=y>M</td><td class=y>238</td><td class=y>BUF</td><td class=y>M</td></tr><tr><td class=x>1G</td><td class=x>3</td><td class=x>BOY</td><td class=x>ne</td><td class=x>157</td><td class=x>BOY</td><td class=x>ne</td></tr><tr><td class=y>2M</td><td class=y>6</td><td class=y>DIM</td><td class=y>M</td><td class=y>106</td><td class=y>MAA</td><td class=y>ak</td></tr><tr><td class=x>5V1, 5V3,</td><td class=x>5</td><td class=x>DIM</td><td class=x>ak6</td><td class=x>106</td><td class=x>BRE</td><td class=x>ak6</td></tr><tr><td class=y>5V1</td><td class=y>2</td><td class=y>SLR</td><td class=y>na2</td><td class=y>205</td><td class=y>HUP</td><td class=y>na2</td></tr></table></center> <BR>";
var SecTeller=0
var wtime = null;
var width,margin;
var tgs = new Array( "div","td","th","pre");
var PageTeller=0;
</SCRIPT>
</body></html>
Met de code die ik in mijn main post heb staan probeer ik dat voor elkaar te krijgen. Maar omdat bijvoorbeeld de tekens " en ; ook voorkomen in de inhoud van PageArray, moet ik die ook bij preg_match gaan vermelden. En dan krijg ik geen resultaten, omdat PHP blijkbaar niet stopt bij het eind ";
Ik zoek dus gewoon een manier om PageArray[0], [1] en [2] te krijgen. Hoe dat gebeurt, maakt mij niet uit, maar preg_match lijkt mij daar de juiste functie voor.
Gewijzigd op 14/09/2012 23:03:51 door Patrick S
hmm reguliere expressies zijn niet mijn sterkste kant maar ik denk dat je eerder zoekt naar preg_match_all ik zou er even op googlen en ik denk dat je wel veel voorbeeldjes krijgt.