I
I
Ivan2021-06-06 20:38:08
PHP
Ivan, 2021-06-06 20:38:08

How to get two parameters from a string?

I get post data in the form of title-desc-2013-04-28
How to pull out the title and desc?

If I do this, I get only the title
$title = trim(strstr($_POST['title'], '-', true));

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HellWalk, 2021-06-06
@9StarRu

$_POST['title'] = 'title-desc-2013-04-28';
$array = explode('-', $_POST['title']);
$title = $array[0];
$desc = $array[1];

var_dump($title); // title
var_dump($desc); // desc

If the php version is fresh, you can do this:
[$title, $desc] = $array;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question