|
|
|
สอบถามเรื่องคำสั่ง ที่เอาค่า ของ XML ทุกค่า ใน tag มาใช้ครับ |
|
|
|
|
|
|
|
Code (PHP)
print_r($xml);
มันได้ค่าเป็น Array หรือเปล่าครับ
|
|
|
|
|
Date :
2014-04-18 09:32:21 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$xml=simplexml_load_string($xml_rates);
print_r($xml);
ได้ค่านี้คัรบ
SimpleXMLElement Object ( [VERSION] => 1.0 [USER_TOKEN] => token [LOGIN_INFO] => SimpleXMLElement Object ( [SYSTEM] => XAS [OPERATOR] => BC [POS] => B2C [AGENCY] => ATTB2C [PASSWORD] => bc ) [SEARCH] => SimpleXMLElement Object ( [FLAGS] => SimpleXMLElement Object ( [RETURNWHEN] => R [PRICEDONLY] => Y [SHOWROOMS] => Y [SHOWBREAK] => Y ) [FORWHOM] => SimpleXMLElement Object ( [FORAGENCY] => ATTB2C [FORCOUNTRY] => SimpleXMLElement Object ( ) ) [SORT] => P [CURRENCY] => THB [STAYPERIOD] => SimpleXMLElement Object ( [CHECKINDATE] => 20140421 [DURATION] => 1 ) [CITY] => BKK [HOTELPARAMS] => SimpleXMLElement Object ( [SERVICE] => SimpleXMLElement Object ( ) [SUBSERVICE] => --- ) [ROOMS] => SimpleXMLElement Object ( [ROOM] => SimpleXMLElement Object ( [QUANTITY] => SimpleXMLElement Object ( ) [ADULT_NO] => 1 [CHILD_NO] => 0 ) ) ) ) Array ( [ "1.0" encoding="utf-8"?> 1.0 token XAS BC B2C ATTB2C bc R Y Y Y ATTB2C P THB 20140421 1 BKK --- 1 0 )
ประเด็นคือมันล้วงไปหาค่าตัวลูกมันไม่ได้อ่ะครับ Y Y ไม่รู้วิธีเอาค่าลูกมันมาแสดงอ่ะ
|
|
|
|
|
Date :
2014-04-18 15:59:36 |
By :
nut |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองนี่ดูครับ
Code (PHP)
function XML2Array(SimpleXMLElement $parent)
{
$array = array();
foreach ($parent as $name => $element) {
($node = & $array[$name])
&& (1 === count($node) ? $node = array($node) : 1)
&& $node = & $node[];
$node = $element->count() ? XML2Array($element) : trim($element);
}
return $array;
}
$xml = simplexml_load_string($xml_rates);
$array = XML2Array($xml);
$array = array($xml->getName() => $array);
|
|
|
|
|
Date :
2014-04-18 16:17:51 |
By :
itpcc |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณน่ะ เด่วจะลองดูครับ
|
|
|
|
|
Date :
2014-04-18 16:26:29 |
By :
nut_ch31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$xmlObj = simplexml_load_string($xmlStr); // สร้างเป็น xml object
$arrXml = objectsIntoArray($xmlObj); // แปลงค่า xml object เป็นตัวแปร array ใน php
function objectsIntoArray($arrObjData, $arrSkipIndices = array())
{
$arrData = array();
// if input is object, convert into array
if (is_object($arrObjData)) {
$arrObjData = get_object_vars($arrObjData);
}
if (is_array($arrObjData)) {
foreach ($arrObjData as $index => $value) {
if (is_object($value) || is_array($value)) {
$value = objectsIntoArray($value, $arrSkipIndices); // recursive call
}
if (in_array($index, $arrSkipIndices)) {
continue;
}
$arrData[$index] = $value;
}
}
return $arrData;
}
ได้ล่ะคัรบ
|
|
|
|
|
Date :
2014-04-18 17:02:20 |
By :
nut_ch31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2014-04-19 08:30:55 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|