當前位置: 首頁>>代碼示例>>PHP>>正文


PHP XML_Serializer::setErrorHandling方法代碼示例

本文整理匯總了PHP中XML_Serializer::setErrorHandling方法的典型用法代碼示例。如果您正苦於以下問題:PHP XML_Serializer::setErrorHandling方法的具體用法?PHP XML_Serializer::setErrorHandling怎麽用?PHP XML_Serializer::setErrorHandling使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在XML_Serializer的用法示例。


在下文中一共展示了XML_Serializer::setErrorHandling方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: array

<?php

/**
 * This example shows how to create an RDF document
 * with a few lines of code.
 * This can also be done with mode => simplexml
 *
 * @author Stephan Schmidt <schst@php.net>
 * @see    serializeIndexedArray.php
 */
error_reporting(E_ALL);
require_once 'XML/Serializer.php';
$options = array("indent" => "    ", "linebreak" => "\n", "typeHints" => false, "addDecl" => true, "encoding" => "UTF-8");
$serializer = new XML_Serializer($options);
$serializer->setErrorHandling(PEAR_ERROR_DIE);
$array = array(new stdClass(), new stdClass());
$result = $serializer->serialize($array);
if ($result === true) {
    echo "<pre>";
    echo htmlentities($serializer->getSerializedData());
    echo "</pre>";
}
$result = $serializer->serialize($array, array('classAsTagName' => true));
if ($result === true) {
    echo "<pre>";
    echo htmlentities($serializer->getSerializedData());
    echo "</pre>";
}
開發者ID:BackupTheBerlios,項目名稱:dilps,代碼行數:28,代碼來源:serializeArrayWithObjects.php

示例2: serializeArray

/**
 * Return xml version of result set.
 */
function serializeArray($resultList)
{
    $options = array(XML_SERIALIZER_OPTION_XML_DECL_ENABLED => false, XML_SERIALIZER_OPTION_DOCTYPE_ENABLED => false, XML_SERIALIZER_OPTION_INDENT => "    ", XML_SERIALIZER_OPTION_LINEBREAKS => "\n", XML_SERIALIZER_OPTION_TYPEHINTS => false, XML_SERIALIZER_OPTION_XML_ENCODING => "UTF-8?", XML_SERIALIZER_OPTION_ROOT_NAME => "results", XML_SERIALIZER_OPTION_DEFAULT_TAG => "result", XML_SERIALIZER_OPTION_CDATA_SECTIONS => true);
    // instatiate the serializer object
    $serializer = new XML_Serializer($options);
    $serializer->setErrorHandling(PEAR_ERROR_DIE);
    // serialze the data
    $status = $serializer->serialize($resultList);
    // check whether serialization worked
    if (PEAR::isError($status)) {
        die($status->getMessage());
    }
    // get the serialized data
    $xml = $serializer->getSerializedData();
    header("Content-type: text/xml; charset=UTF-8");
    //header("Content-Transfer-Encoding: binary\n");
    // return the xml
    $xml = html_entity_decode($xml, ENT_QUOTES, 'UTF-8');
    $xml = stripslashes($xml);
    $xml = trim($xml);
    echo $xml;
}
開發者ID:raedatoui,項目名稱:View,代碼行數:25,代碼來源:functions.php


注:本文中的XML_Serializer::setErrorHandling方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。