S
S
simonnidze2016-04-14 13:23:10
PHP
simonnidze, 2016-04-14 13:23:10

Parse a string in php into an array?

There are two options for the strings First Name Last Name1,2 and First Name Last Name
I need to get arrays of the form Array("name"=>"First Name Last Name", "num"=> "1,2") and Array ("name"=>"I. O. Surname", "num"=> "")
How can this be done in the simplest way?
Examples:
T. A. Kolpakova2,3
A. V. Chechushkov1

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
vdem, 2016-04-14
@simonnidze

/(.*?)([\d,]+)/
UPD:
/^(.*?)([\d,]+)?$/

E
Evgeny Akhmetov, 2016-04-14
@asperin2

preg_match_all('|(.+)(\d?.*)|', $str, $matches);

D
DuD, 2016-04-14
@DuD

([A-Z]\. [A-Z]\. [A-Z]*)([,0-9].*)?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question