I
I
Ifoxik2020-05-10 02:45:35
PHP
Ifoxik, 2020-05-10 02:45:35

How to split a string into variables in PHP?

There is a line with data of this kind. How to split it into variables in order to get:
info date=17/month=Feb/year=2019/new/

echo $date; // 17
echo $month; // Feb
echo $year; // 2019

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daria Motorina, 2020-05-10
@Ifoxik

https://www.phpliveregex.com/p/vSE

T
ThunderCat, 2020-05-10
@ThunderCat

parse_str(str_replace('/','&',$str), $output);
var_dump($output);
extract($output);
Keep in mind that dumping variables from an unknown source into the current context, you run the risk of running into substitution of current variables for left values, or, when using the EXTR_SKIP flag, implicit behavior. Ideally, use the array obtained from parsing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question