php – 像Wordcode一样解析WordPress
发布时间:2020-12-13 13:30:26 所属栏目:PHP教程 来源:网络整理
导读:我想解析像Wordpress这样的短代码: 输入: [include file="header.html"] 我需要输出作为数组,函数名称“包含”和属性值,任何帮助将不胜感激. 谢谢 使用 this function $code = '[include file="header.html"]';$innerCode = GetBetween($code,'[',']');$in
我想解析像Wordpress这样的短代码:
输入: [include file="header.html"] 我需要输出作为数组,函数名称“包含”和属性值,任何帮助将不胜感激. 谢谢
使用
this function
$code = '[include file="header.html"]'; $innerCode = GetBetween($code,'[',']'); $innerCodeParts = explode(' ',$innerCode); $command = $innerCodeParts[0]; $attributeAndValue = $innerCodeParts[1]; $attributeParts = explode('=',$attributeParts); $attribute = $attributeParts[0]; $attributeValue = str_replace('"','',$attributeParts[1]); echo $command . ' ' . $attribute . '=' . $attributeValue; //this will result in include file=header.html $command将是“include” $属性将是“文件” $attributeValue将是“header.html” (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |