Delimiter vraag

Status
Niet open voor verdere reacties.

infernothebest

Gebruiker
Lid geworden
25 feb 2008
Berichten
76
IK heb deze text en wil alles individueel kunnen benaderen wat tussen | staat. de text hieronder weergeeft mijn voorbeeld text, het probleem is dat ik het nu niet krijg gesplitst.


Code:
 || | | | | | | | | | | | | | | | | | | | | | | || | | | | | |IP5-1hc-DS-C102DSIP5-1hcC102|IP5-1hc-DS-C102DSIP5-1hcC102|IP5-1hc-DS-C102DSIP5-1hcC102|PV5-1hc-ZA-C002ZAPV5-1hcC002|PV5-1hc-ZA-C002ZAPV5-1hcC002| |PV5-2pb-ZA-D413ZAPV5-2pbD413,D414|PV5-2pb-ZA-D413ZAPV5-2pbD413,D414|PV5-2pb-ZA-D413ZAPV5-2pbD413,D414|IP5-2po-n.v.t.-D413n.v.t.IP5-2poD413,D414|IP5-2po-n.v.t.-D413n.v.t.IP5-2poD413,D414|IP5-2po-n.v.t.-D413n.v.t.IP5-2poD413,D414| | | | | || |VP5-1wc-BZ-C202BZVP5-1wcC202|VP5-1wc-BZ-C202BZVP5-1wcC202|VP5-1wc-BZ-C202BZVP5-1wcC202|VP5-1wc-BZ-C202BZVP5-1wcC202|VP5-1wc-BZ-C202BZVP5-1wcC202|VP5-1wc-BZ-C202BZVP5-1wcC202| |IP5-4fb-AZ-D413AZ,DSIP5-4fbD413,C207|IP5-4fb-AZ-D413AZ,DSIP5-4fbD413,C207|IP5-4fb-AZ-D413AZ,DSIP5-4fbD413,C207| | | | | | | | | | | | || | | | | | | | |IP5-8hc-VM-B102VMIP5-8hcB102|IP5-8hc-VM-B102VMIP5-8hcB102|IP5-8hc-VM-B102VMIP5-8hcB102| |IP5-5pb-AZ-D414AZ,DSIP5-5pbD414,D413|IP5-5pb-AZ-D414AZ,DSIP5-5pbD414,D413| | | | | | | | | || |PV5-3fb-ZA-C006ZAPV5-3fbC006|PV5-3fb-ZA-C006ZAPV5-3fbC006| | | | | | | | | | | | | | | | | | | | |


Ik gebruik deze code:

PHP:
$dom = new domDocument; 
libxml_use_internal_errors(true);
$dom->loadHTML($html); 
$dom->preserveWhiteSpace = false; 
$tables = $dom->getElementsByTagName('table'); 
$rows = $tables->item(0)->getElementsByTagName('tr'); 
foreach ($rows as $row){ 
$cols = $row->getElementsByTagName('td'); 


$pizza  = $cols->item(0)->nodeValue."|";
$pieces = explode("|", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
}


en krijg dit als output ipv bv "Â", hij zet alles in $pieces[0]; en doet dit niet opsplitten


Code:
                              IP5-1hc-DS-C102DSIP5-1hcC102IP5-1hc-DS-C102DSIP5-1hcC102IP5-1hc-DS-C102DSIP5-1hcC102PV5-1hc-ZA-C002ZAPV5-1hcC002PV5-1hc-ZA-C002ZAPV5-1hcC002 PV5-2pb-ZA-D413ZAPV5-2pbD413,D414PV5-2pb-ZA-D413ZAPV5-2pbD413,D414PV5-2pb-ZA-D413ZAPV5-2pbD413,D414IP5-2po-n.v.t.-D413n.v.t.IP5-2poD413,D414IP5-2po-n.v.t.-D413n.v.t.IP5-2poD413,D414IP5-2po-n.v.t.-D413n.v.t.IP5-2poD413,D414      VP5-1wc-BZ-C202BZVP5-1wcC202VP5-1wc-BZ-C202BZVP5-1wcC202VP5-1wc-BZ-C202BZVP5-1wcC202VP5-1wc-BZ-C202BZVP5-1wcC202VP5-1wc-BZ-C202BZVP5-1wcC202VP5-1wc-BZ-C202BZVP5-1wcC202 IP5-4fb-AZ-D413AZ,DSIP5-4fbD413,C207IP5-4fb-AZ-D413AZ,DSIP5-4fbD413,C207IP5-4fb-AZ-D413AZ,DSIP5-4fbD413,C207                    IP5-8hc-VM-B102VMIP5-8hcB102IP5-8hc-VM-B102VMIP5-8hcB102IP5-8hc-VM-B102VMIP5-8hcB102 IP5-5pb-AZ-D414AZ,DSIP5-5pbD414,D413IP5-5pb-AZ-D414AZ,DSIP5-5pbD414,D413          PV5-3fb-ZA-C006ZAPV5-3fbC006PV5-3fb-ZA-C006ZAPV5-3fbC006                   Â


als ik de code anders formuleer om te zien hoe de array er uit ziet dan krijg je dit te zien

Code:
Array ( [0] => Â  [1] => ) Array ( [0] => [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => IP5-1hc-DS-C102DSIP5-1hcC102 [1] => ) Array ( [0] => IP5-1hc-DS-C102DSIP5-1hcC102 [1] => ) Array ( [0] => IP5-1hc-DS-C102DSIP5-1hcC102 [1] => ) Array ( [0] => PV5-1hc-ZA-C002ZAPV5-1hcC002 [1] => ) Array ( [0] => PV5-1hc-ZA-C002ZAPV5-1hcC002 [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => PV5-2pb-ZA-D413ZAPV5-2pbD413,D414 [1] => ) Array ( [0] => PV5-2pb-ZA-D413ZAPV5-2pbD413,D414 [1] => ) Array ( [0] => PV5-2pb-ZA-D413ZAPV5-2pbD413,D414 [1] => ) Array ( [0] => IP5-2po-n.v.t.-D413n.v.t.IP5-2poD413,D414 [1] => ) Array ( [0] => IP5-2po-n.v.t.-D413n.v.t.IP5-2poD413,D414 [1] => ) Array ( [0] => IP5-2po-n.v.t.-D413n.v.t.IP5-2poD413,D414 [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => VP5-1wc-BZ-C202BZVP5-1wcC202 [1] => ) Array ( [0] => VP5-1wc-BZ-C202BZVP5-1wcC202 [1] => ) Array ( [0] => VP5-1wc-BZ-C202BZVP5-1wcC202 [1] => ) Array ( [0] => VP5-1wc-BZ-C202BZVP5-1wcC202 [1] => ) Array ( [0] => VP5-1wc-BZ-C202BZVP5-1wcC202 [1] => ) Array ( [0] => VP5-1wc-BZ-C202BZVP5-1wcC202 [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => IP5-4fb-AZ-D413AZ,DSIP5-4fbD413,C207 [1] => ) Array ( [0] => IP5-4fb-AZ-D413AZ,DSIP5-4fbD413,C207 [1] => ) Array ( [0] => IP5-4fb-AZ-D413AZ,DSIP5-4fbD413,C207 [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => IP5-8hc-VM-B102VMIP5-8hcB102 [1] => ) Array ( [0] => IP5-8hc-VM-B102VMIP5-8hcB102 [1] => ) Array ( [0] => IP5-8hc-VM-B102VMIP5-8hcB102 [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => IP5-5pb-AZ-D414AZ,DSIP5-5pbD414,D413 [1] => ) Array ( [0] => IP5-5pb-AZ-D414AZ,DSIP5-5pbD414,D413 [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => PV5-3fb-ZA-C006ZAPV5-3fbC006 [1] => ) Array ( [0] => PV5-3fb-ZA-C006ZAPV5-3fbC006 [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => ) Array ( [0] => Â  [1] => )
 
Laatst bewerkt:
Volgens mij klopt het wel. Omdat er geen newline in de tekst of in de code staat wordt alles achter elkaar geplaatst en lijkt het alsof alles in $pieces[0] zit, maar zoals je kan zien in de array bestaat de array wel uit afzonderlijke elementen.
Verander je "echo's" eens in:
PHP:
echo $pieces[0] . "\n";
echo $pieces[1] . "\n";
of zelfs in
PHP:
echo "0: " . $pieces[0] . "\n";
echo "1: " . $pieces[1] . "\n";
Dan kan je zien wat er op elke positie in de array staat.
 
bedankt voor het reageren, maar het had helaas niet geholpen alle informatie zit in pieces[0] ipv gesplitst, als je naar de array kijkt zie je ook dat alles daar in zit
 
Ik heb het eens geprobeerd met dit script:
PHP:
<?php
$pizza = "Â ||Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â ||Â |Â |Â |Â |Â |Â |IP5-1hc-DS-C102DSIP5-1hcC102|IP5-1hc-DS-C102DSIP5-1hcC102|IP5-1hc-DS-C102DSIP5-1hcC102|PV5-1hc-ZA-C002ZAPV5-1hcC002|PV5-1hc-ZA-C002ZAPV5-1hcC002|Â |PV5-2pb-ZA-D413ZAPV5-2pbD413,D414|PV5-2pb-ZA-D413ZAPV5-2pbD413,D414|PV5-2pb-ZA-D413ZAPV5-2pbD413,D414|IP5-2po-n.v.t.-D413n.v.t.IP5-2poD413,D414|IP5-2po-n.v.t.-D413n.v.t.IP5-2poD413,D414|IP5-2po-n.v.t.-D413n.v.t.IP5-2poD413,D414|Â |Â |Â |Â |Â ||Â |VP5-1wc-BZ-C202BZVP5-1wcC202|VP5-1wc-BZ-C202BZVP5-1wcC202|VP5-1wc-BZ-C202BZVP5-1wcC202|VP5-1wc-BZ-C202BZVP5-1wcC202|VP5-1wc-BZ-C202BZVP5-1wcC202|VP5-1wc-BZ-C202BZVP5-1wcC202|Â |IP5-4fb-AZ-D413AZ,DSIP5-4fbD413,C207|IP5-4fb-AZ-D413AZ,DSIP5-4fbD413,C207|IP5-4fb-AZ-D413AZ,DSIP5-4fbD413,C207|Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â ||Â |Â |Â |Â |Â |Â |Â |Â |IP5-8hc-VM-B102VMIP5-8hcB102|IP5-8hc-VM-B102VMIP5-8hcB102|IP5-8hc-VM-B102VMIP5-8hcB102|Â |IP5-5pb-AZ-D414AZ,DSIP5-5pbD414,D413|IP5-5pb-AZ-D414AZ,DSIP5-5pbD414,D413|Â |Â |Â |Â |Â |Â |Â |Â |Â ||Â |PV5-3fb-ZA-C006ZAPV5-3fbC006|PV5-3fb-ZA-C006ZAPV5-3fbC006|Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |Â |";
$pieces = explode("|", $pizza);
foreach ($pieces as $piece)
{
        echo $piece . "\n";
}
?>
Dan krijg ik alles netjes onder elkaar:
frank@darkstar:~$ php /tmp/split2.php
Â

Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â

Â
Â
Â
Â
Â
Â
IP5-1hc-DS-C102DSIP5-1hcC102
IP5-1hc-DS-C102DSIP5-1hcC102
IP5-1hc-DS-C102DSIP5-1hcC102
PV5-1hc-ZA-C002ZAPV5-1hcC002
PV5-1hc-ZA-C002ZAPV5-1hcC002
Â
PV5-2pb-ZA-D413ZAPV5-2pbD413,D414
PV5-2pb-ZA-D413ZAPV5-2pbD413,D414
PV5-2pb-ZA-D413ZAPV5-2pbD413,D414
IP5-2po-n.v.t.-D413n.v.t.IP5-2poD413,D414
IP5-2po-n.v.t.-D413n.v.t.IP5-2poD413,D414
IP5-2po-n.v.t.-D413n.v.t.IP5-2poD413,D414
Â
Â
Â
Â
Â

Â
VP5-1wc-BZ-C202BZVP5-1wcC202
VP5-1wc-BZ-C202BZVP5-1wcC202
VP5-1wc-BZ-C202BZVP5-1wcC202
VP5-1wc-BZ-C202BZVP5-1wcC202
VP5-1wc-BZ-C202BZVP5-1wcC202
VP5-1wc-BZ-C202BZVP5-1wcC202
Â
IP5-4fb-AZ-D413AZ,DSIP5-4fbD413,C207
IP5-4fb-AZ-D413AZ,DSIP5-4fbD413,C207
IP5-4fb-AZ-D413AZ,DSIP5-4fbD413,C207
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â

Â
Â
Â
Â
Â
Â
Â
Â
IP5-8hc-VM-B102VMIP5-8hcB102
IP5-8hc-VM-B102VMIP5-8hcB102
IP5-8hc-VM-B102VMIP5-8hcB102
Â
IP5-5pb-AZ-D414AZ,DSIP5-5pbD414,D413
IP5-5pb-AZ-D414AZ,DSIP5-5pbD414,D413
Â
Â
Â
Â
Â
Â
Â
Â
Â

Â
PV5-3fb-ZA-C006ZAPV5-3fbC006
PV5-3fb-ZA-C006ZAPV5-3fbC006
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â

Werkt dat script wel goed?

[edit]Welke array heb je trouwens bekeken (laatste regel van je eerste post)? Het lijkt namelijk een array van arrays te zijn.[/edit]
 
Laatst bewerkt:
ik heb het opgelost gekregen, met behulp van dit voorbeeld :)

@$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
$tables = $dom->getElementsByTagName('table');
$rows = $tables->item(0)->getElementsByTagName('tr');
$rr = array();
foreach($rows as $text =>$row) {
$cols = $row->getElementsByTagName('td');
$rr[] = $cols->item(0)->nodeValue;
}


Echo "Maandag";
echo "8:30 - 9:00 ".$rr[3]. ”</br>“;
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan