|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I'm using the simplexml class to parse through some xml. when i use
the standard foreach loop syntax, i get the expected results. <?php foreach ($xml->item as $artist) { echo $artist->title "<br />"; }?> Outputs: Kinky Matchbox Twenty When i use the alternate syntax of: <?php foreach ($xml->item as $artist):?> echo "$artist->title <br />"; <?php endforeach; ?> It Outpusts: echo "$artist->title "; echo "$artist->title "; Am i doing something wrong? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
> When i use the alternate syntax of:
> <?php foreach ($xml->item as $artist):?> > echo "$artist->title <br />"; > <?php endforeach; ?> > > It Outpusts: > echo "$artist->title > "; echo "$artist->title > "; > > Am i doing something wrong? Yes. You leave the echo statement to the HTML output, not to the PHP parser. So the alternative syntax version is: <?php foreach ($xml->item as $artist): echo "$artist->title <br />"; endforeach; ?> This works with almost all structures (except class, function and try). Best regards. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Thanks!
|
|
![]() |
| Outils de la discussion | |
|
|