2016-06-16 6 views
-2

Ich habe eine Array-Daten, die Daten zeigt, aber ich möchte es in Listenelemente verwenden, z. ul und li-Tags, aber ich weiß nicht, die genaue Art und Weise, wie kann ich es tun hier ist die Probe, die ich will kann while oder foreach Schleife verwenden istPHP-Array-Daten in Listenelemente

<ul> 
    <li>Demo Item 1</li> 
    <li>Demo Description 1</li> 
    <li>http://demo-site.com/1</li> 
</ul> 

<ul> 
    <li>Demo Item 2</li> 
    <li>Demo Description 2</li> 
    <li>http://demo-site.com/2</li> 
</ul> 

<ul> 
    <li>Demo Item 3</li> 
    <li>Demo Description 3</li> 
    <li>http://demo-site.com/3</li> 
</ul> 

<ul> 
    <li>Demo Item 4</li> 
    <li>Demo Description 4</li> 
    <li>http://demo-site.com/4</li> 
</ul> 

<ul> 
    <li>Demo Item 5</li> 
    <li>Demo Description 5</li> 
    <li>http://demo-site.com/5</li> 
</ul> 

Hier meine PHP-Code:

<?php 
include_once('simple_html_dom.php'); 
$xml = simplexml_load_file('http://mywebsite-addr/stats.xml'); 
$parsed_results_array = array(); 
foreach($xml as $entry) { 
    foreach($entry->match as $item) { 
     // $parsed_results_array[] = json_decode(json_encode($item), true); 
     $items['title'] = (string) $item->opponent->name; 
     $items['description'] = (string) $item->result; 
     $items['link'] = (string) $item->url; 
     $items['time'] = (string) $item->date; 
     $parsed_results_array[] = $items; 
    } 
} 

echo '<pre>'; 
print_r($parsed_results_array); 
echo '</pre>'; 
?> 

Hier ist die Arraydaten, dass Sie kann

Array 
(
    [0] => Array 
     (
      [title] => Demo Item 1 
      [description] => Demo Description 1 
      [link] => http://demo-site.com/1 
      [time] => Wed 15 Jun 2016, 11:30 PM EDT 
     ) 

    [1] => Array 
     (
      [title] => Demo Item 2 
      [description] => Demo Description 2 
      [link] => http://demo-site.com/2 
      [time] => Wed 15 Jun 2016, 10:00 PM EDT 
     ) 

    [2] => Array 
     (
      [title] => Demo Item 3 
      [description] => Demo Description 3 
      [link] => http://demo-site.com/4 
      [time] => Wed 15 Jun 2016, 12:45 AM EDT 
     ) 

    [3] => Array 
     (
      [title] => Demo Item 4 
      [description] => Demo Description 4 
      [link] => http://demo-site.com/4 
      [time] => Tue 14 Jun 2016, 11:45 PM EDT 
     ) 

    [4] => Array 
     (
      [title] => Demo Item 5 
      [description] => Demo Description 5 
      [link] => http://demo-site.com/5 
      [time] => Tue 14 Jun 2016, 10:00 PM EDT 
     ) 

) 
+2

Wir sind uns keine freie Codierung Service, bitte zeigen, was Sie, um versucht haben den gewünschten Ausgang und umfassen alle Fehler bekommen Sie – Epodax

Antwort

0
helfen
+0

es andere Möglichkeiten, um Ihre Abzeichen zu bekommen ist bekommen könnte – Wolfeh

0

dieses Versuchen ohne zusätzliche Array zu erstellen:

include_once('simple_html_dom.php'); 
$xml = simplexml_load_file('http://mywebsite-addr/stats.xml'); 
$parsed_results_array = array(); 

foreach($xml as $entry) { 
    foreach($entry->match as $item) { 
     echo '<ul>'; 
     echo '<li>' . (string) $item->opponent->name . '</li>'; 
     echo '<li>' . (string) $item->result . '</li>'; 
     echo '<li>' . (string) $item->url . '</li>'; 
     echo '</ul>'; 
    } 
} 
+0

Ist '(String) 'notwendig hier und was ist seine Rolle hier ?? Bitte entferne '$ parsed_results_array = array(); 'da es hier nichts tut, nehme ich an ... –

+1

wie du weißt (string) wird für typecast verwendet. –

+0

Ja, ich weiß, aber ich frage, was es seine Rolle in einfachen 'Echo-Wert'? –

0

Sie wirklich nicht, entweder Array benötigen, aber zumindest fallen diese Linie

$parsed_results_array[] = $items; 

und ersetzen sie durch

echo " 
<ul> 
<li>$items[title]</li> 
<li>$items[description]</li> 
<li>$items[link]</li> 
</ul> 
"; 
1

Templating alternativ e:

<?php 
    // Some nice php code here ... 
?> 

<?php foreach($parsed_results_array as $result): ?> 
<ul> 
    <?php foreach($result as $data): ?> 
    <li><?php echo $data ?></li> 
    <?php endforeach ?> 
</ul> 
<?php endforeach ?>  

<?php 
    // Some other php code there ... 
?> 
+0

FYI die '

+1

@JeffPuckettII Aktualisiert, vielen Dank für Ihre Eingabe. –