像简码一样解析Wordpress [英] Parse Wordpress like Shortcode

查看:72
本文介绍了像简码一样解析Wordpress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想解析诸如Wordpress之类的带有属性的短代码:

I want to parse shortcode like Wordpress with attributes:

输入:

[include file="header.html"]

我需要输出为数组,函数名称"include"以及具有值的属性,任何帮助将不胜感激.

I need output as array, function name "include" and attributes with values as well , any help will be appreciated.

谢谢

推荐答案

使用此功能

$code = '[include file="header.html"]';
$innerCode = GetBetween($code, '[', ']');
$innerCodeParts = explode(' ', $innerCode);

$command = $innerCodeParts[0];

$attributeAndValue = $innerCodeParts[1];
$attributeParts = explode('=', $attributeAndValue);
$attribute = $attributeParts[0];
$attributeValue = str_replace('"', '', $attributeParts[1]);

echo $command . ' ' . $attribute . '=' . $attributeValue;
//this will result in include file=header.html

$ command将为"include"

$command will be "include"

$ attribute将是文件"

$attribute will be "file"

$ attributeValue将为"header.html"

$attributeValue will be "header.html"

这篇关于像简码一样解析Wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆