本文整理汇总了PHP中xml_to_array函数的典型用法代码示例。如果您正苦于以下问题:PHP xml_to_array函数的具体用法?PHP xml_to_array怎么用?PHP xml_to_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xml_to_array函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: xml_to_array
/**
* XML转成数组 (XML to array)
* @param string $xml XML字符串
* @return array
*/
function xml_to_array($xml)
{
if (stripos($xml, '<?xml') !== false) {
$xml = preg_replace('/<\\?xml.*?\\?>/is', '', $xml);
}
$result = array();
$pattern = '/<\\s*(.*?)(\\s+.*?)?>(.*?)<\\s*\\/\\s*\\1\\s*>/is';
preg_match_all($pattern, $xml, $matches);
if (!empty($matches[3][0])) {
foreach ($matches[3] as $key => $value) {
preg_match_all($pattern, $value, $matches_v);
if (!empty($matches_v[3][0])) {
$ret = xml_to_array($value);
} else {
$ret = $value;
}
if (array_key_exists($matches[1][$key], $result) && !empty($result[$matches[1][$key]])) {
if (is_array($result[$matches[1][$key]]) && array_key_exists(0, $result[$matches[1][$key]])) {
$result[$matches[1][$key]][] = $ret;
} else {
$result[$matches[1][$key]] = array($result[$matches[1][$key]], $ret);
}
} else {
$result[$matches[1][$key]] = $ret;
}
}
}
return $result;
}
开发者ID:ToogleLiu,项目名称:code,代码行数:34,代码来源:xml_to_array.php
示例2: sendSMS
public function sendSMS()
{
$post_code = isset($_POST['post_code']) ? $_POST['post_code'] : '';
$phone_num = isset($_POST['telephone']) ? $_POST['telephone'] : '';
// $post_code='U2FsdGVkX1+zY61T/9h6KxyTBWVwbNR9Z01QjZN5EmT5BzDIEROXMFb9it8VgTrW
// Yippi/B79Y0u+ZXJMwSLXGo8imoz9OTrB3k0uhvjIEyi4pF27xCm/Cg0pW0T3SoS
// 9oCORpIFF/600rCAvhDsMOADCKCBtvLhpL4YpLKHQ3/jqQFsjWF8YUVMc0x9LtPa
// 3eeGQIFsdRDr2nSWMlnGQExvNvyKnfLWUrH+YkJDIJlYzXihdv32yMw+vCf/DDa2
// Oq4CU2BkzLqff4IjGmA/9+FP2SS19kDMzdf5e1DO132QBhHDrLy1ffrSIabFRHVf
// SVDsy1qZSsC7Ea24RdmQBQ==';
if ($phone_num == '') {
return show(103, '手机号不能为空');
}
if (preg_match('/^1[34578][0-9]{9}$/', $phone_num)) {
} else {
return show(101, '手机号格式不正确');
}
$mobile_code = random(6, 1);
//random()是公共自定义函数
$target = "http://106.ihuyi.cn/webservice/sms.php?method=Submit";
$post_data = "account=cf_guoqingyu&password=luping521&mobile=" . $phone_num . "&content=" . rawurlencode("您的校验码是:" . $mobile_code . "。请不要把校验码泄露给其他人。如非本人操作,可不用理会!");
//密码可以使用明文密码或使用32位MD5加密
$gets = xml_to_array(Post($post_data, $target));
if ($gets['SubmitResult']['code'] == 2) {
S('phone_num', $phone_num, 60);
S($phone_num . 'mobile_code', $mobile_code, 60);
return show(104, '发送成功');
} else {
return show(102, '发送失败');
}
}
开发者ID:283541486,项目名称:kaixinwa2.0,代码行数:31,代码来源:SmsController.class.php
示例3: xml_to_array
function xml_to_array($root)
{
$result = array();
if ($root->hasAttributes()) {
$attrs = $root->attributes;
foreach ($attrs as $attr) {
$result['@attributes'][$attr->name] = $attr->value;
}
}
if ($root->hasChildNodes()) {
$children = $root->childNodes;
if ($children->length == 1) {
$child = $children->item(0);
if ($child->nodeType == XML_TEXT_NODE) {
$result['_value'] = $child->nodeValue;
return count($result) == 1 ? $result['_value'] : $result;
}
}
$groups = array();
foreach ($children as $child) {
if (!isset($result[$child->nodeName])) {
$result[$child->nodeName] = xml_to_array($child);
} else {
if (!isset($groups[$child->nodeName])) {
$result[$child->nodeName] = array($result[$child->nodeName]);
$groups[$child->nodeName] = 1;
}
$result[$child->nodeName][] = xml_to_array($child);
}
}
}
return $result;
}
开发者ID:Alex--Jin,项目名称:shopify_private_fillz,代码行数:33,代码来源:general_functions.php
示例4: xml_to_array
function xml_to_array($xml)
{
$reg = "/<(\\w+)[^>]*?>([\\x00-\\xFF]*?)<\\/\\1>/";
if (preg_match_all($reg, $xml, $matches)) {
$count = count($matches[0]);
$arr = array();
for ($i = 0; $i < $count; $i++) {
$key = $matches[1][$i];
$val = xml_to_array($matches[2][$i]);
// 递归
if (array_key_exists($key, $arr)) {
if (is_array($arr[$key])) {
if (!array_key_exists(0, $arr[$key])) {
$arr[$key] = array($arr[$key]);
}
} else {
$arr[$key] = array($arr[$key]);
}
$arr[$key][] = $val;
} else {
$arr[$key] = $val;
}
}
return $arr;
} else {
return $xml;
}
}
开发者ID:LightStrawberry,项目名称:wechatApp,代码行数:28,代码来源:index.php
示例5: xml_to_array
function xml_to_array($xml)
{
$fils = 0;
$tab = false;
$array = array();
foreach ($xml->children() as $key => $value) {
$child = xml_to_array($value);
//To deal with the attributes
//foreach ($node->attributes() as $ak => $av) {
// $child[$ak] = (string)$av;
//}
//Let see if the new child is not in the array
if ($tab == false && in_array($key, array_keys($array))) {
//If this element is already in the array we will create an indexed array
$tmp = $array[$key];
$array[$key] = NULL;
$array[$key][] = $tmp;
$array[$key][] = $child;
$tab = true;
} elseif ($tab == true) {
//Add an element in an existing array
$array[$key][] = $child;
} else {
//Add a simple element
$array[$key] = $child;
}
$fils++;
}
if ($fils == 0) {
return (string) $xml;
}
return $array;
}
开发者ID:nomaan-alkurn,项目名称:thooth,代码行数:33,代码来源:xml_to_array.php
示例6: xml_to_array
function xml_to_array($xml_object)
{
$out = array();
foreach ((array) $xml_object as $index => $node) {
$out[$index] = is_object($node) ? xml_to_array($node) : $node;
}
return (array) $out;
}
开发者ID:tfont,项目名称:skyfire,代码行数:8,代码来源:xml_to_array.func.php
示例7: xml_to_array
protected function xml_to_array($xml_object)
{
if (defined('STRICT_TYPES') && CAMEL_CASE == '1') {
return (array) self::parameters(['xml_object' => DT::TYPE_ARRAY])->call(__FUNCTION__)->with($xml_object)->returning(DT::TYPE_ARRAY);
} else {
return (array) xml_to_array($xml_object);
}
}
开发者ID:tfont,项目名称:skyfire,代码行数:8,代码来源:xml.class.php
示例8: discover_api
function discover_api()
{
// designed to run the built in api functions (if the exist) to get valid values for some api method calls
$idTypes = new SimpleXMLElement($this->getIdTypes());
$this->idTypes = xml_to_array($idTypes, 'idTypeList', 'idName');
$relaTypes = new SimpleXMLElement($this->getRelaTypes());
$this->relaTypes = xml_to_array($relaTypes, 'relationTypeList', 'relationType');
$sourceTypes = new SimpleXMLElement($this->getSourceTypes());
$this->sourceTypes = xml_to_array($sourceTypes, 'sourceTypeList', 'sourceName');
}
开发者ID:songhongji,项目名称:gaiaehr,代码行数:10,代码来源:rxNormApi.php
示例9: xmltoarray
function xmltoarray($xml)
{
if ($xml) {
$arr = xml_to_array($xml);
$key = array_keys($arr);
return $arr[$key[0]];
} else {
return '';
}
}
开发者ID:shitfSign,项目名称:ducter-web,代码行数:10,代码来源:dcmd_util_func.php
示例10: test_items
/**
* @ticket UT32
*/
function test_items()
{
$this->go_to('/feed/');
$feed = $this->do_rss2();
$xml = xml_to_array($feed);
// get all the rss -> channel -> item elements
$items = xml_find($xml, 'rss', 'channel', 'item');
$posts = get_posts('numberposts=' . $this->post_count);
// check each of the items against the known post data
for ($i = 0; $i < $this->post_count; $i++) {
// title
$title = xml_find($items[$i]['child'], 'title');
$this->assertEquals($posts[$i]->post_title, $title[0]['content']);
// link
$link = xml_find($items[$i]['child'], 'link');
$this->assertEquals(get_permalink($posts[$i]->ID), $link[0]['content']);
// comment link
$comments_link = xml_find($items[$i]['child'], 'comments');
$this->assertEquals(get_permalink($posts[$i]->ID) . '#comments', $comments_link[0]['content']);
// pub date
$pubdate = xml_find($items[$i]['child'], 'pubDate');
$this->assertEquals(strtotime($posts[$i]->post_date), strtotime($pubdate[0]['content']));
// author
$creator = xml_find($items[$i]['child'], 'dc:creator');
$this->assertEquals($this->author->user_nicename, $creator[0]['content']);
// categories (perhaps multiple)
$categories = xml_find($items[$i]['child'], 'category');
$cat_ids = wp_get_post_categories($post->ID);
if (empty($cat_ids)) {
$cat_ids = array(1);
}
// should be the same number of categories
$this->assertEquals(count($cat_ids), count($categories));
// ..with the same names
for ($j = 0; $j < count($cat_ids); $j++) {
$this->assertEquals(get_cat_name($cat_ids[$j]), $categories[$j]['content']);
}
// GUID
$guid = xml_find($items[$i]['child'], 'guid');
$this->assertEquals('false', $guid[0]['attributes']['isPermaLink']);
$this->assertEquals($posts[$i]->guid, $guid[0]['content']);
// description/excerpt
$description = xml_find($items[$i]['child'], 'description');
$this->assertEquals(trim($posts[$i]->post_excerpt), trim($description[0]['content']));
// post content
if (!$this->excerpt_only) {
$content = xml_find($items[$i]['child'], 'content:encoded');
$this->assertEquals(trim(apply_filters('the_content', $posts[$i]->post_content)), trim($content[0]['content']));
}
// comment rss
$comment_rss = xml_find($items[$i]['child'], 'wfw:commentRss');
$this->assertEquals(html_entity_decode(get_post_comments_feed_link($posts[$i]->ID)), $comment_rss[0]['content']);
}
}
开发者ID:boonebgorges,项目名称:wp,代码行数:57,代码来源:rss2.php
示例11: testToArray
public function testToArray()
{
$content = '<foo>
<bar hello="hello world">
Hello
</bar>
</foo>';
$array_data = xml_to_array($content);
$this->assertTrue(is_array($array_data));
// Array
//(
// [0] => Array
// (
// [tag] => FOO
// [type] => open
// [level] => 1
// [value] =>
//
// )
//
// [1] => Array
// (
// [tag] => BAR
// [type] => complete
// [level] => 2
// [attributes] => Array
// (
// [HELLO] => hello world
// )
//
// [value] => Hello
// )
//
// [2] => Array
// (
// [tag] => FOO
// [value] =>
// [type] => cdata
// [level] => 1
// )
//
// [3] => Array
// (
// [tag] => FOO
// [type] => close
// [level] => 1
// )
//
// )
//)
}
开发者ID:parsilver,项目名称:functions,代码行数:51,代码来源:XmlTest.php
示例12: get_xml
function get_xml($id)
{
$folder = $this->dir_root . "plugins/" . $id . "/";
if (!is_dir($folder)) {
return false;
}
$rs = array();
if (is_file($folder . "config.xml")) {
$rs = xml_to_array(file_get_contents($folder . "config.xml"));
}
$rs["id"] = $id;
$rs["path"] = $folder;
return $rs;
}
开发者ID:renlong567,项目名称:43168,代码行数:14,代码来源:plugin.php
示例13: send_sms
function send_sms($phoneNumber, $message)
{
global $smsUserName, $smsPassword;
$target = "http://106.ihuyi.cn/webservice/sms.php?method=Submit";
$userName = $smsUserName;
$passWord = $smsPassword;
$post_data = "account={$userName}&password={$passWord}&mobile={$phoneNumber}&content=" . rawurlencode($message);
$gets = xml_to_array(send_server($post_data, $target));
$ret = "";
if ($gets['SubmitResult']['code'] == 2) {
return true;
} else {
printResultByMessage($gets['SubmitResult']['msg'], 109);
}
}
开发者ID:qichangjun,项目名称:HTMLLearn,代码行数:15,代码来源:sms.php
示例14: actionMonitorTask
public function actionMonitorTask($task_id)
{
$task = DcmdTask::findOne($task_id);
///非系统管理员只能操作同一产品组的该任务
if (Yii::$app->user->getIdentity()->admin != 1) {
if ($task->opr_uid != Yii::$app->user->getId()) {
///判断是否为同一产品组
$app = DcmdApp::findOne($task->app_id);
$query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $app['svr_gid']]);
if ($query == NULL) {
Yii::$app->getSession()->setFlash('success', NULL);
Yii::$app->getSession()->setFlash('error', "对不起,你没有权限!");
return $this->redirect(array('dcmd-task/index'));
}
}
} else {
///系统管理员产品所属同一系统组
$app = DcmdApp::findOne($task->app_id);
$query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $app['sa_gid']]);
if ($query == NULL) {
Yii::$app->getSession()->setFlash('success', NULL);
Yii::$app->getSession()->setFlash('error', "对不起,你没有权限!");
return $this->redirect(array('dcmd-task/index'));
}
}
if (Yii::$app->request->post()) {
$timeout = Yii::$app->request->post()['timeout'];
$auto = Yii::$app->request->post()['auto'];
$concurrent_rate = Yii::$app->request->post()['concurrent_rate'];
$this->updateTask($task_id, $timeout, $auto, $concurrent_rate);
////var_dump(Yii::$app->request->post());exit;
}
///获取产品名称
///$query = DcmdService::findOne($task->svr_id);
$app_id = $task->app_id;
/// $query->app_id;
///$query = DcmdApp::findOne($app_id);
$app_name = $task->app_name;
$ret = xml_to_array($task->task_arg);
$args = "";
if (is_array($ret['env'])) {
foreach ($ret['env'] as $k => $v) {
$args .= $k . '=' . $v . " ; ";
}
}
return $this->render('monitor', ['task_id' => $task_id, 'task' => $task, 'args' => $args, 'app_name' => $app_name, 'app_id' => $app_id]);
}
开发者ID:shitfSign,项目名称:ducter-web,代码行数:47,代码来源:DcmdTaskAsyncController.php
示例15: xml_to_array
public static function xml_to_array($xml)
{
$reg = "/<(\\w+)[^>]*>([\\x00-\\xFF]*)<\\/\\1>/";
if (preg_match_all($reg, $xml, $matches)) {
$count = count($matches[0]);
for ($i = 0; $i < $count; $i++) {
$subxml = $matches[2][$i];
$key = $matches[1][$i];
if (preg_match($reg, $subxml)) {
$arr[$key] = xml_to_array($subxml);
} else {
$arr[$key] = $subxml;
}
}
}
return $arr;
}
开发者ID:TipTimesPHP,项目名称:tyj_oa,代码行数:17,代码来源:sendSMS.class.php
示例16: invokeGetMatchingProductForId
function invokeGetMatchingProductForId(MarketplaceWebServiceProducts_Interface $service, $request)
{
try {
$response = $service->GetMatchingProductForId($request);
$dom = new DOMDocument();
$dom->loadXML($response->toXML());
$arrResult = xml_to_array($dom);
return $arrResult;
} catch (MarketplaceWebServiceProducts_Exception $ex) {
echo "Caught Exception: " . $ex->getMessage() . "\n";
echo "Response Status Code: " . $ex->getStatusCode() . "\n";
echo "Error Code: " . $ex->getErrorCode() . "\n";
echo "Error Type: " . $ex->getErrorType() . "\n";
echo "Request ID: " . $ex->getRequestId() . "\n";
echo "XML: " . $ex->getXML() . "\n";
echo "ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n";
}
}
开发者ID:Alex--Jin,项目名称:shopify_private_fillz,代码行数:18,代码来源:mws_lookup.php
示例17: load
/**
* 加载数据 数组 或XML
* @param array $data 格式: 微信键名=>键值
* @param xml $data 格式: 微信标准的XML
* @return Object
*/
public function load($data, $denyxml)
{
if (is_array($data)) {
$this->type = 0;
$this->data = $data;
} else {
$postObj = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
if ($postObj instanceof SimpleXMLElement) {
$packet = array();
$packet = xml_to_array($postObj, array('ToUserName', 'FromUserName', 'CreateTime'));
$this->type = 1;
$this->data = $packet;
} else {
$this->type = 2;
$this->data['Content'] = $data;
}
}
return $this;
}
开发者ID:fedkey,项目名称:amango,代码行数:25,代码来源:Factory.class.php
示例18: GetProductInfoByTitle
function GetProductInfoByTitle($title)
{
$conf = new GenericConfiguration();
try {
$conf->setCountry('com')->setAccessKey(AWS_API_KEY)->setSecretKey(AWS_API_SECRET_KEY)->setAssociateTag(AWS_ASSOCIATE_TAG);
} catch (\Exception $e) {
echo $e->getMessage();
}
$apaiIO = new ApaiIO($conf);
$search = new Search();
// $lookup->setItemId('B0040PBK32,B00MEKHLLA');
$search->setCategory('Books');
$search->setKeywords($title);
$formattedResponse = $apaiIO->runOperation($search);
$dom = new DOMDocument();
$dom->loadXML($formattedResponse);
$arrResponse = xml_to_array($dom);
return $arrResponse;
}
开发者ID:Alex--Jin,项目名称:shopify_private_fillz,代码行数:19,代码来源:amazon_lookup.php
示例19: send
public function send($nickName, $sendName, $openid, $minValue, $maxValue, $wishing, $actName, $remark)
{
//发送红包
$this->nickName = $nickName;
$this->sendName = $sendName;
$this->openid = $openid;
$this->minValue = $minValue;
$this->maxValue = $maxValue;
$this->wishing = $wishing;
$this->remake = $remark;
$this->actName = $actName;
$sendValue = rand($minValue, $maxValue);
$xmlData = $this->createXml($sendValue);
$returnStr = xml_to_array($this->postXmlSSLCurl($xmlData, $this->url));
//正确返回信息,写返回状态SUCCESS,写库
if (isset($returnStr['return_code']) && $returnStr['return_code'] == "SUCCESS" && $returnStr['result_code'] == "SUCCESS") {
$WechatRedpacketModel = new WechatRedpacketModel();
$WechatRedpacketModel->addData($nickName, $sendName, $openid, $minValue, $maxValue, $sendValue, $wishing, $actName, $remark, $returnStr);
}
}
开发者ID:yunzhiclub,项目名称:wemall,代码行数:20,代码来源:SendRedGiftController.class.php
示例20: actionView
/**
* Displays a single DcmdTaskHistory model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
$task = $this->findModel($id);
$app_id = $task->app_id;
////$query->app_id;
$app_name = $task->app_name;
$ret = xml_to_array($task->task_arg);
$args = "";
if (is_array($ret['env'])) {
foreach ($ret['env'] as $k => $v) {
$args .= $k . '=' . $v . " ; ";
}
}
///服务池子
$query = DcmdTaskServicePoolHistory::find()->andWhere(['task_id' => $id]);
$svr_dataProvider = new ActiveDataProvider(['query' => $query]);
$svr_searchModel = new DcmdTaskServicePoolHistorySearch();
///未运行的任务
$con = array('task_id' => $id, 'state' => 0);
$query = DcmdTaskNodeHistory::find()->andWhere($con)->orderBy("utime desc")->limit(5);
$init_dataProvider = new ActiveDataProvider(['query' => $query]);
$init_searchModel = new DcmdTaskNodeHistorySearch();
///在运行
$con = array('task_id' => $id, 'state' => 1);
$query = DcmdTaskNodeHistory::find()->andWhere($con)->orderBy("utime desc")->limit(5);
$run_dataProvider = new ActiveDataProvider(['query' => $query]);
$run_searchModel = new DcmdTaskNodeHistorySearch();
///失败任务
$con = array('task_id' => $id, 'state' => 3);
$query = DcmdTaskNodeHistory::find()->andWhere($con)->orderBy("utime desc")->limit(5);
$fail_dataProvider = new ActiveDataProvider(['query' => $query]);
$fail_searchModel = new DcmdTaskNodeHistorySearch();
///完成任务
$con = array('task_id' => $id, 'state' => 2);
$query = DcmdTaskNodeHistory::find()->andWhere($con)->orderBy("utime desc")->limit(5);
$suc_dataProvider = new ActiveDataProvider(['query' => $query]);
$suc_searchModel = new DcmdTaskNodeHistorySearch();
return $this->render('monitor', ['task' => $task, 'app_id' => $app_id, 'app_name' => $app_name, 'args' => $args, 'svr_dataProvider' => $svr_dataProvider, 'svr_searchModel' => $svr_searchModel, 'init_dataProvider' => $init_dataProvider, 'init_searchModel' => $init_searchModel, 'run_dataProvider' => $run_dataProvider, 'run_searchModel' => $run_searchModel, 'fail_dataProvider' => $fail_dataProvider, 'fail_searchModel' => $fail_searchModel, 'suc_dataProvider' => $suc_dataProvider, 'suc_searchModel' => $suc_searchModel]);
}
开发者ID:shitfSign,项目名称:ducter-web,代码行数:44,代码来源:DcmdTaskHistoryController.php
注:本文中的xml_to_array函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论