Reputation: 167
I have a input box called 'str_local_og_fb_admins' and I want that input box to be able to have more than one admin, like if I input in the form "1234,5678" I want the return to be:
<meta property="fb:admins" content="1234">
<meta property="fb:admins" content="5678">
I'm able to create one tag only like if I put this in my form "1234,5678" it returns:
<meta property="fb:admins" content="1234,5678">
I'm working at a octobercms plugin to handle open graph tags and that is the only problem I'm having, here is the input field I created(it's created at the plugin.php file):
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');
I output the tags using a component I have created, this is how my default.htm of that component looks like:
{% if this.page.str_local_og_fb_admins %}
<meta property="fb:admins" content="{{this.page.str_local_og_fb_admins}}">
{% endif %}
I also set in the database the field as string. (My plugin is a backend plugin, all my forms only appear in the backend pages)
Upvotes: 1
Views: 287
Reputation: 10333
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
The answer is trivial, use explode
function in PHP for this:
$str = "123,321";
$pieces = explode(",", $str);
echo $pieces[0]; // "123"
echo $pieces[1]; // "321"
Upvotes: 1