Разобрать текст предложения SQL SELECT и создать массив, содержащий каждый столбец/выражение.Php

Кемеровские программисты php общаются здесь
Anonymous
Разобрать текст предложения SQL SELECT и создать массив, содержащий каждый столбец/выражение.

Сообщение Anonymous »

У меня есть следующая строка:

Код: Выделить всё

$str = "am_customers.customer_key,am_customers.add_dt,CONCAT(am_customers.first_name,'',am_customers.last_name) as name,am_customers.cell_phone,am_customers.crm_phase_key,am_customers.source,am_customers.location_key,am_customers.hub_key,am_customers.crm_priority,am_customers.update_dt";
Я хочу разделить строку по запятой. Но проблема связана с открывающими и закрывающими скобками. Когда я пытаюсь разбить строку на запятую, я получаю следующий результат:

Код: Выделить всё

Array
(
[0] => am_customers.customer_key
[1] => am_customers.add_dt
[2] => CONCAT(am_customers.first_name
[3] => ''
[4] => am_customers.last_name) as name
[5] => am_customers.cell_phone
[6] => am_customers.crm_phase_key
[7] => am_customers.source
[8] => am_customers.location_key
[9] => am_customers.hub_key
[10] => am_customers.crm_priority
[11] => am_customers.update_dt
)
Но мне нужен следующий результат:

Код: Выделить всё

Array
(
[0] => am_customers.customer_key
[1] => am_customers.add_dt
[2] => CONCAT(am_customers.first_name,'',am_customers.last_name) as name
[3] => am_customers.last_name) as name
[4] => am_customers.cell_phone
[5] => am_customers.crm_phase_key
[6] => am_customers.source
[7] => am_customers.location_key
[8] => am_customers.hub_key
[9] => am_customers.crm_priority
[10] => am_customers.update_dt
)
Есть ли способ сделать это так, как я хочу выше?

Подробнее здесь: https://stackoverflow.com/questions/453 ... n-expressi

Вернуться в «Php»