Answer the question
In order to leave comments, you need to log in
Extract only text from string via regexp regexp?
There are dynamic lines:
20 black/grey 20 black/
grey
20 black/grey/white 20 black/grey
/white
That is, numbers and so on can be added first. It is necessary to receive only what is separated by the sign "/"
In order to then split it into an array through explode.
Please help me with the regular expression . Otherwise
, my knowledge ended at the level [.*^ ].*\/.* and she is looking for the current 1 example
Answer the question
In order to leave comments, you need to log in
$text = '20 черный/серый
20черный/серый
20 черный/серый/белый
20черный/серый/белый';
$strings = preg_split('/\n/s', $text, null, PREG_SPLIT_NO_EMPTY);
$strings = array_map(function ($val){
return explode('/', trim(preg_replace('/^\d+/', '', $val)));
}, $strings);
print_r($strings);
Array
(
[0] => Array
(
[0] => черный
[1] => серый
)
[1] => Array
(
[0] => черный
[1] => серый
)
[2] => Array
(
[0] => черный
[1] => серый
[2] => белый
)
[3] => Array
(
[0] => черный
[1] => серый
[2] => белый
)
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question