2017-01-30 9 views
0

もう一度私はあなたの助けを求めます。私はExcelの情報を提供するXMLを持っています。この抜粋に含まれているすべての情報(MAIL USER PASS)をXML。PHPのExcel XML情報を抽出する

<Row> 
 
<Cell ss:StyleID="s62" ss:HRef="mailto:[email protected]"> 
 
<Data ss:Type="String">[email protected]</Data> 
 
</Cell> 
 
<Cell> 
 
<Data ss:Type="String">: user: Joao || Pass : user3</Data> 
 
</Cell> 
 
</Row> 
 
<Row> 
 
<Cell ss:StyleID="s62" ss:HRef="mailto:[email protected]"> 
 
<Data ss:Type="String">[email protected]</Data> 
 
</Cell> 
 
<Cell> 
 
<Data ss:Type="String">: user: Carlos || Pass : user4</Data> 
 
</Cell> 
 
</Row> 
 
<Row> 
 
<Cell ss:StyleID="s62" ss:HRef="mailto:[email protected]"> 
 
<Data ss:Type="String">[email protected]</Data> 
 
</Cell> 
 
<Cell> 
 
<Data ss:Type="String">: user: Paulo || Pass : user1</Data> 
 
</Cell> 
 
</Row> 
 
<Row> 
 
<Cell ss:StyleID="s62" ss:HRef="mailto:[email protected]"> 
 
<Data ss:Type="String">[email protected]</Data> 
 
</Cell> 
 
<Cell> 
 
<Data ss:Type="String">: user: Ricardo || Pass : user52</Data> 
 
</Cell> 
 
</Row> 
 
<Row> 
 
<Cell ss:StyleID="s62" ss:HRef="mailto:[email protected]"> 
 
<Data ss:Type="String">[email protected]</Data> 
 
</Cell> 
 
<Cell> 
 
<Data ss:Type="String">: user: santos || Pass : user9</Data> 
 
</Cell> 
 
</Row>

私はエコーPHPで文書を持っているが、私は、上のボックスにあり、私はこの問題を解決する上で、あなたの助けを求めるようになってきている情報を取得することはできません。

は、私は私の問題を解決する上で助けのための完全なXMLリンク(http://trabalhos.6te.net/TesteXML.xml)とも

<?php 
 
$data = array(); 
 
    
 
function add_person($first, $middle, $last, $email) 
 
{ 
 
global $data; 
 
    
 
$data []= array(
 
'first' => $first, 
 
'middle' => $middle, 
 
'last' => $last, 
 
'email' => $email 
 
); 
 
} 
 
    
 
if ($_FILES['file']['tmp_name']) 
 
{ 
 
$dom = DOMDocument::load($_FILES['http://trabalhos.6te.net/TesteXML.xml']['tmp_name']); 
 
$rows = $dom->getElementsByTagName('Row'); 
 
$first_row = true; 
 
foreach ($rows as $row) 
 
{ 
 
if (!$first_row) 
 
{ 
 
$first = ""; 
 
$middle = ""; 
 
$last = ""; 
 
$email = ""; 
 
    
 
$index = 1; 
 
$cells = $row->getElementsByTagName('Cell'); 
 
foreach($cells as $cell) 
 
{ 
 
$ind = $cell->getAttribute('Index'); 
 
if ($ind != null) $index = $ind; 
 
    
 
if ($index == 1) $first = $cell->nodeValue; 
 
if ($index == 2) $middle = $cell->nodeValue; 
 
if ($index == 3) $last = $cell->nodeValue; 
 
if ($index == 4) $email = $cell->nodeValue; 
 
    
 
$index += 1; 
 
} 
 
add_person($first, $middle, $last, $email); 
 
} 
 
$first_row = false; 
 
} 
 
} 
 
?> 
 
<html> 
 
<body> 
 
<table> 
 
<tr> 
 
<th>First</th> 
 
<th>Middle</th> 
 
<th>Last</th> 
 
<th>Email</th> 
 
</tr> 
 
<?php foreach($data as $row) { ?> 
 
<tr> 
 
<td><?php echo($row['first']); ?></td> 
 
<td><?php echo($row['middle']); ?></td> 
 
<td><?php echo($row['last']); ?></td> 
 
<td><?php echo($row['email']); ?></td> 
 
</tr> 
 
<?php } ?> 
 
</table> 
 
</body> 
 
</html>

感謝最初にすべてのエコーのphpを残して取り付けられています。

+0

私は目標を理解していません。 XMLから情報を抽出する必要があります.HTMLテーブルに入れますか?または、XMLから情報を削除したいですか? –

+0

@OscarZarrus HTMLテーブルのXML情報を削除したいのですが、できません。 –

+0

申し訳ありません、多分私は少し愚かですが、私はあなたの目標に到達することはできません。出力例を作成してください。 –

答えて

0

我々は、配列の中にXMLを解析する前のステップ

一歩を始めましょう:それは、この配列を生成します

$xmlFile = file_get_contents("http://trabalhos.6te.net/TesteXML.xml"); 
$xml = new SimpleXMLElement($xmlFile); 
$Rows = $xml->Worksheet->Table; // take the Worksheet tag from object and take Table inside it... 
$i = 0; 
$results = array(); 
// loop through the user data 
foreach ($Rows->Row as $r){ 
    if ($i === 0){$i++;continue;} 
    $email = (array)$r->Cell[0]->Data; 
    $email = $email[0]; 
    $user = (array)$r->Cell[1]->Data; 
    $user = $user[0]; 

    $results[] = array(
      'email' => $email, 
      'user' => $user 
    ); 
    $i++; 

} 

Array 
(
    [0] => Array 
     (
      [email] => [email protected] 
      [user] => : user: Joao || Pass : user3 
     ) 

    [1] => Array 
     (
      [email] => [email protected] 
      [user] => : user: Carlos || Pass : user4 
     ) 

    [2] => Array 
     (
      [email] => [email protected] 
      [user] => : user: Paulo || Pass : user1 
     ) 

    [3] => Array 
     (
      [email] => [email protected] 
      [user] => : user: Ricardo || Pass : user52 
     ) 

    [4] => Array 
     (
      [email] => [email protected] 
      [user] => : user: santos || Pass : user9 
     ) 

) 
関連する問題