The example of this article describes the XML operation (reading) encapsulation class implemented by PHP. Share it with everyone for your reference, the details are as follows:
<?xml version="1.0" encoding="utf-8" standalone="no"?> <CustomizationSetting version='1.0' > <!-- 各通用配置信息,作为Settings子节点,方便统一解析 --> <!-- AgentSettings 由网页定制生成,默认无次节点--> <AgentSettings> <!-- 以Setting 作为节点名,考虑扩展时,不需修改客户端接口。 type类型方便网页进行显示控件区分 --> <!-- 代理定制类型,默认:Normal。在网页区分语言定制的情况下,以英文、或列表第一种语言的修改为准 --> <Setting name='CustomizeType' type='enum'>Normal|DR</Setting> <!-- 产品名称,AgentType为DR时,用于获取代理购买地址 --> <Setting name='AppName' type='string'>Wondershare Vedio Convertor</Setting> <!-- 品牌名称,AgentType为DR时,用于获取代理购买地址 --> <Setting name='Publisher' type='string'>Wondershare</Setting> <!-- 购买地址生成方式,默认:Customize,由网页生成,默认无次节点 --> <Setting name='OrderPageGenType' type='enum'>Customize|Affiliate</Setting> <!-- Affiliate ID, OrderPageGenType为Affiliate才有效,默认为空值 --> <Setting name='AID' type='string'>143724583</Setting> <!-- 启动Affiliat 购买地址启用短链接, OrderPageGenType为Affiliate才有效,默认:0 --> <Setting name='UseShortAffiliateOrderLink' type='bool'>0|1</Setting> <!-- 定制输出名称 --> <Setting name='OutputFileName' type='string'><![CDATA[1464646.mac-transpod-lite_full879.dmg]]></Setting> </AgentSettings> <!-- 各语言定制信息,作为Languages子节点,方便统一解析, 以及扩展 --> <Languages> <!-- 语言名称,统一使用CBS后台语言数据规范 --> <Language name='English' > <Settings> <!-- 产品ID,多语言中可被定制 --> <Setting name='PID' type='stirng'>11642</Setting> <!-- 支持弹出广告,默认:1,最终能否弹广告还取决于网站的设置,这里主要用于关闭的总控制 --> <Setting name='EnabelAD' type='bool'>1|0</Setting> <!-- 支持升级,默认:1 --> <Setting name='EnableUpdate' type='bool'>1|0</Setting> <!-- CBS跳转链接类型,只对InstallJumpPage,UninstallJumpPage,RegisterJumpPage,UpdateJumpPage有效,默认:Jump --> <Setting name='CBSJumpType' type='enum'>Jump|Hide|Disable</Setting> <!-- 支持Tisp消息--> <Setting name='TipsEnable' type='bool'>1|0</Setting> <!-- 支持弹出产品目录推荐, 默认:1--> <Setting name='EnableProductSuit' type='bool'>1|0</Setting> </Settings> <!-- 链接地址作为URLS子节点,方便统一解析 --> <URLS> <!-- 不使用'**Page'直接作为节点名称,避免自定义地址的名称与XML节点名称规范冲突,如就数字开头,同时支持网页界面根据不同产品显示链接名称,而且扩展时,而不需修改客户端接口 --> <!-- 购买地址。属性updateReserve表示产品升级保留定制信息,默认:0, 进入定制页面后,默认修改为1 --> <!-- 区分地址类型order, jump, comm, custom方便网页显示归类 --> <URL name='OrderPage' type='order' updateReserve='0|1'><![CDATA[http://www.php.cn/]]></URL> <!-- 安装跳转地址。属性updateReserve表示产品升级保留定制信息,默认:0, 进入定制页面后,默认修改为1 --> <URL name='InstallJumpPage' type='jump' updateReserve='0|1'><![CDATA[http://www.php.cn/]]></URL> <!-- 卸载跳转地址,Mac产品无此项。属性updateReserve表示产品升级保留定制信息,默认:0, 进入定制页面后,默认修改为1 --> <URL name='UninstallJumpPage' type='jump' updateReserve='0|1'><![CDATA[http://www.php.cn/]]></URL> <!-- 注册跳转地址。属性updateReserve表示产品升级保留定制信息,默认:0, 进入定制页面后,默认修改为1 --> <URL name='RegisterJumpPage' type='jump' updateReserve='0|1'><![CDATA[http://www.php.cn/]]></URL> <!-- 升级跳转地址。属性updateReserve表示产品升级保留定制信息,默认:0, 进入定制页面后,默认修改为1 --> <URL name='UpdateJumpPage' type='jump' updateReserve='0|1'><![CDATA[http://www.php.cn/]]></URL> <!-- 公司主页地址。属性updateReserve表示产品升级保留定制信息,默认:0, 进入定制页面后,默认修改为1 --> <URL name='HomePage' type='comm' updateReserve='0|1'><![CDATA[http://www.php.cn/]]></URL> <!-- 产品主页地址。属性updateReserve表示产品升级保留定制信息,默认:0, 进入定制页面后,默认修改为1 --> <URL name='ProductPage' type='comm' updateReserve='0|1'><![CDATA[http://www.php.cn/]]></URL> <!-- 支持地址。属性updateReserve表示产品升级保留定制信息,默认:0, 进入定制页面后,默认修改为1 --> <URL name='SupportPage' type='comm' updateReserve='0|1'><![CDATA[http://www.php.cn/]]></URL> <!-- 联系客服地址。属性updateReserve表示产品升级保留定制信息,默认:0, 进入定制页面后,默认修改为1 --> <URL name='ContactPage' type='comm' updateReserve='0|1'><![CDATA[http://www.php.cn/]]></URL> <!-- 在线帮助地址。属性updateReserve表示产品升级保留定制信息,默认:0, 进入定制页面后,默认修改为1 --> <URL name='HelpOnlinePage' type='comm' updateReserve='0|1'><![CDATA[http://www.php.cn/]]></URL> <!-- 自定义地址,最多可定义5个。属性updateReserve表示产品升级保留定制信息,默认:0, 进入定制页面后,默认修改为1 --> <URL name='3DPage' type='custom' updateReserve='0|1'><![CDATA[http://www.php.cn/]]></URL> <!-- 自定义地址,最多可定义5个。属性updateReserve表示产品升级保留定制信息,默认:0, 进入定制页面后,默认修改为1 --> <URL name='GPUPage' type='custom' updateReserve='0|1'><![CDATA[http://www.php.cn/]]></URL> </URLS> <!-- 待扩展信息,在客户端接口中预先处理 --> </Language> <!-- 产品不支持某种语言,则不需要该<Language>节点 --> <Language name='Traditional Chinese(HK)'> <!-- 同上 --> </Language> <Language name='Chinese'> <!-- 同上 --> </Language> <Language name='Portuguese'> <!-- 同上 --> </Language> <Language name='Japanese'> <!-- 同上 --> </Language> <Language name='Korean'> <!-- 同上 --> </Language> <Language name='Hebrew'> <!-- 同上 --> </Language> <Language name='Arabic'> <!-- 同上 --> </Language> <Language name='Spanish'> <!-- 同上 --> </Language> <Language name='Polish'> <!-- 同上 --> </Language> <Language name='German'> <!-- 同上 --> </Language> <Language name='French'> <!-- 同上 --> </Language> <Language name='Italian'> <!-- 同上 --> </Language> <Language name='Spanish(Spain)'> <!-- 同上 --> </Language> <Language name='Spanish(Mexico)'> <!-- 同上 --> </Language> <Language name='Traditional Chinese(TW)'> <!-- 同上 --> </Language> <Language name='Dutch'> <!-- 同上 --> </Language> <Language name='Russian'> <!-- 同上 --> </Language> </Languages> </CustomizationSetting>
Encapsulates the read xml operation class:
<?php /** * xml操作基类 */ class XmlBase { public function __construct() { } /** * 加载xml * @param string $xml xml路径或xml字符串 * @param bool $isXmlStr 是否是xml字符串 */ protected function _loadXml($xml, $isXmlStr = FALSE) { $xmlObj = new DOMDocument(); if ($isXmlStr) { $xmlObj->loadXML($xmlNewStr); } else { $xmlObj->load($xml); } return $xmlObj; } /** * 获取某个标签节点 * @param $parentnode 父节点 * @param $tagName 标签名 // 不区分大小写 * @return node 节点对象 */ protected function _getNode($parentNode, $tagName) { $childNodes = $this->_getNodes($parentNode); foreach ($childNodes as $node) { $nodeName = strtolower(trim($node->nodeName)); $tagName = strtolower(trim($tagName)); if ($nodeName == $tagName) { return $node; } } return NULL; } /** * 获取xml子节点 * @param $parentNode 父节点 * @param $tagName 子节点标签 // 不区分大小写 */ protected function _getNodes($parentNode, $tagName = '') { $nodes = array(); if ($tagName) { $nodes = $this->_getSpecialNodes($parentNode, $tagName); } else { $nodes = $this->_getAllNodes($parentNode); } return $nodes; } /** * 获取所有的节点 * @param $parentNode 父节点 */ protected function _getAllNodes($parentNode) { $nodes = array(); foreach ($parentNode->childNodes as $node) { if ($node->nodeType == 1) { $nodes[] = $node; } } return $nodes; } /** * 获取指定标签的节点 * @param $parentNode 父节点 * @param $tagName 节点名称 */ protected function _getSpecialNodes($parentNode, $tagName) { $nodes = array(); $tagName = strtolower(trim($tagName)); foreach ($parentNode->childNodes as $node) { $nodeName = strtolower(trim($node->nodeName)); if ($node->nodeType == 1 && $nodeName == $tagName) { $nodes[] = $node; } } return $nodes; } /** * 获取节点属性值 * * @param $node 节点对象 * @param $attrName 节点名字 // 不区分大小写 */ protected function _getAttr($node, $attrName) { $attrName = strtolower($attrName); foreach ($node->attributes as $attr) { $nodeName = strtolower($attr->nodeName); //$nodeValue = strtolower($attr->nodeValue); $nodeType = strtolower($attr->nodeType); if ($nodeType == 2 && $nodeName == $attrName) { unset($attrName, $nodeName, $nodeType); return $attr->nodeValue; } } return ''; } } ?>
For more articles related to PHP’s XML operation (reading) encapsulation class examples, please pay attention to the PHP Chinese website!

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Mac version
God-level code editing software (SublimeText3)

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
