2017-07-27 4 views
0

単純なテキストをXML形式に解析したいと考えています。私はそれをするために多くのことを試みたが、私はそれを行うことができません。CodeIgniterを使用して文字列をXMLに変換する方法

私はコードの下にしようとしている:

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 

class Home extends CI_Controller { 

public function index() 
{ 
    $url = "https:myURL"; 
    $data = array("username" => "USERID"); 
    //$ctype = array("Content-Type" => "text/xml"); 
    $this->curl->create($url); 
    //$this->curl->http_header("Content-Type", "application/xml"); 
    $this->curl->http_header("Accept", "application/xml"); 
    //$this->curl->http_header("charset", "UTF-8"); 
    $this->curl->option(CURLOPT_HTTPHEADER, array('Content-type: 
    application/xml-dtd')); 
    $this->curl->post($data); 
    $xml = $this->curl->execute(); 
    $xml = new SimpleXMLElement($xml); 
    print_r($xml); 
    exit; 
    $this->load->view('home_view'); 
} 
} 

が、私はこのコードを実行した後に、この出力を取得しています。

SimpleXMLElement Object ([responseId] => 290 [status] => SUCCESS [result] => SimpleXMLElement Object ([seed] => 426477071456611)) 

が、私の要件は、次のようなものです:どのように私はこの出力を得ることができます

<?xml version="1.0" encoding="utf-8"?> 
<response> 
    <responseId>246</responseId> 
    <status>SUCCESS</status> 
<result> 
    <seed>292174305068328</seed> 
</result> 
</response> 

答えて

1
$this->output->set_content_type('text/xml', 'UTF-8');  
print($xml); 
+0

私はこのエラーを取得しています:私は私の問題を解決そんなにありがとうどういたしまして –

+0

上のメンバ関数asXML()の呼び出し –

+0

....文字列 – Oluwaseye

関連する問題