如何在 octobercms 上使用 php 从单个表单输入框创建数组?
How do I create an array from a single form input box with php on octobercms?
我有一个名为 'str_local_og_fb_admins' 的输入框,我希望该输入框能够拥有多个管理员,例如如果我以“1234,5678”的形式输入我想要 return 为:
<meta property="fb:admins" content="1234">
<meta property="fb:admins" content="5678">
我只能创建一个标签,就像我把它放在我的表格“1234,5678”中一样 returns:
<meta property="fb:admins" content="1234,5678">
我正在使用 octobercms 插件来处理开放图形标签,这是我遇到的唯一问题,这是我创建的输入字段(它是在 plugin.php 文件中创建的):
if (!$widget->model instanceof \Cms\Classes\Page) return;
$widget->addFields([
'settings[str_local_og_fb_admins]' => [
'label' => 'Facebook Admins',
'type' => 'text',
'placeholder' => 'Example: 1234',
'tab' => 'Facebook Tags',
]], 'primary');
我使用我创建的组件输出标签,这就是我的 default.htm 该组件的样子:
{% if this.page.str_local_og_fb_admins %}
<meta property="fb:admins" content="{{this.page.str_local_og_fb_admins}}">
{% endif %}
我还在数据库中将字段设置为字符串。
(我的插件是后台插件,我所有的表单只出现在后台页面)
I have one form field and if I input there "123,321" it gives me the
value "123,321" but I want it to give me 123 and 321 separately,
basicly I want to split a string into an array
答案很简单,为此使用 PHP 中的 explode
函数:
$str = "123,321";
$pieces = explode(",", $str);
echo $pieces[0]; // "123"
echo $pieces[1]; // "321"
我有一个名为 'str_local_og_fb_admins' 的输入框,我希望该输入框能够拥有多个管理员,例如如果我以“1234,5678”的形式输入我想要 return 为:
<meta property="fb:admins" content="1234">
<meta property="fb:admins" content="5678">
我只能创建一个标签,就像我把它放在我的表格“1234,5678”中一样 returns:
<meta property="fb:admins" content="1234,5678">
我正在使用 octobercms 插件来处理开放图形标签,这是我遇到的唯一问题,这是我创建的输入字段(它是在 plugin.php 文件中创建的):
if (!$widget->model instanceof \Cms\Classes\Page) return;
$widget->addFields([
'settings[str_local_og_fb_admins]' => [
'label' => 'Facebook Admins',
'type' => 'text',
'placeholder' => 'Example: 1234',
'tab' => 'Facebook Tags',
]], 'primary');
我使用我创建的组件输出标签,这就是我的 default.htm 该组件的样子:
{% if this.page.str_local_og_fb_admins %}
<meta property="fb:admins" content="{{this.page.str_local_og_fb_admins}}">
{% endif %}
我还在数据库中将字段设置为字符串。 (我的插件是后台插件,我所有的表单只出现在后台页面)
I have one form field and if I input there "123,321" it gives me the value "123,321" but I want it to give me 123 and 321 separately, basicly I want to split a string into an array
答案很简单,为此使用 PHP 中的 explode
函数:
$str = "123,321";
$pieces = explode(",", $str);
echo $pieces[0]; // "123"
echo $pieces[1]; // "321"