barbashin-andrey / shortcode
PHP 短代码处理器
v1.0.0
2024-04-22 05:53 UTC
This package is not auto-updated.
Last update: 2024-09-24 06:01:15 UTC
README
基于Wordpress源代码,用于个人用途
示例
require_once __DIR__.'/vendor/autoload.php';
function sampleFunc($params) {
$atts = $params["atts"];
$args = $params["args"];
$name = $atts["name"];
$age = $args["age"];
return "<p>Name: $name</p><p>Age: $age</p>";
}
$content = '
<p>Some other elements</p>
[sample name="Alex"]
<p>Some other elements</p>
';
$handler = new ShortcodeHandler();
$handler->addShortcode('sample', 'sampleFunc', ['age' => 18]);
$content = $handler->handle($content);
print_r($content);
结果
<p>Some other elements</p>
<p>Name: Alex</p><p>Age: 18</p>
<p>Some other elements</p>
安装
通过composer
composer require barbashin-andrey/shortcode