Analyzing a string

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
musicmouse
New php-forum User
New php-forum User
Posts: 4
Joined: Fri Jan 04, 2019 5:04 am

Mon May 20, 2019 1:34 am

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?
chorn
php-forum GURU
php-forum GURU
Posts: 612
Joined: Fri Apr 01, 2016 2:18 am

Mon May 20, 2019 2:17 am

So you need something like a "php sql tokenizer"
musicmouse
New php-forum User
New php-forum User
Posts: 4
Joined: Fri Jan 04, 2019 5:04 am

Tue May 28, 2019 4:23 am

A tokenizer? That what you might call such a thing when you are in compiler building.

But this can just be a regexp formula.
chorn
php-forum GURU
php-forum GURU
Posts: 612
Joined: Fri Apr 01, 2016 2:18 am

Tue May 28, 2019 4:36 am

if you already know that what's the problem making one?
musicmouse
New php-forum User
New php-forum User
Posts: 4
Joined: Fri Jan 04, 2019 5:04 am

Thu May 30, 2019 3:00 am

If you don't know what you are talking about, why do you react?
chorn
php-forum GURU
php-forum GURU
Posts: 612
Joined: Fri Apr 01, 2016 2:18 am

Mon Jun 03, 2019 6:26 am

that problem is already solved and i told you the way.
Post Reply