我想解析像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”