Page 1 of 1

Analyzing a string

Posted: Mon May 20, 2019 1:34 am
by musicmouse
I want to analyze an exported sql file. A line looks something like this:

Code: Select all

(2427, NULL, 'htmlbox', NULL, '2018-12-31')
That should be converted into an array with one entry for each field. So like:

Code: Select all

$myarray = array(2427, NULL, 'htmlbox', NULL, '2018-12-31')
As you see some fields are within quotes, others not - and that is not predictable. Also strings may contain escaped quotes.

Does someone know an algoritm to do this in a clean way?

Re: Analyzing a string

Posted: Mon May 20, 2019 2:17 am
by chorn
So you need something like a "php sql tokenizer"

Re: Analyzing a string

Posted: Tue May 28, 2019 4:23 am
by musicmouse
A tokenizer? That what you might call such a thing when you are in compiler building.

But this can just be a regexp formula.

Re: Analyzing a string

Posted: Tue May 28, 2019 4:36 am
by chorn
if you already know that what's the problem making one?

Re: Analyzing a string

Posted: Thu May 30, 2019 3:00 am
by musicmouse
If you don't know what you are talking about, why do you react?

Re: Analyzing a string

Posted: Mon Jun 03, 2019 6:26 am
by chorn
that problem is already solved and i told you the way.