PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php // Исходный текст $text = " id: 17740 type_id: 1 invitation_type[name]: dealer invitation_type[order]: 2 invitation_type[id]: 1 type: Retail Showroom area_id: address: test suite: 123 zip: 60007 city: ELK GROVE VILLAGE state: IL phone: (345) 234-5234 email: test@gmail.com dba: 555 created: 2023-08-08 02:27:33 default: true residential_home: true mailing_address: true fabrication_shop: true home_office: true showroom[suite]: showroom[zip]: showroom[city]: showroom[state]: showroom[id]: 6801 showroom[profile_id]: 4 showroom[address_id]: 17740 showroom[created]: 2023-08-08 02:27:31 showroom[livingstone_colors][]: 55 showroom[livingstone_colors][]: 65 showroom[vadara_colors][]: 97 showroom[vadara_colors][]: 98 showroom[vadara_towers][]: 12 showroom[vadara_slabs][]: 97 invitation[address_id]: 17740 invitation[field_as_title]: company name invitation[created]: 2023-08-29 06:36:18 invitation[created_by]: Admin invitation[warehouse]: 0 invitation[id]: 3554 invitation[status]: invitation[history_statuses][0][created]: 2023-08-08 02:27:50 invitation[history_statuses][0][id]: 7828 invitation[history_statuses][0][invitation_id]: 3554 invitation[history_statuses][0][site]: www.vadaraquartz.com invitation[history_statuses][0][status]: Submitted invitation[history_statuses][0][comment]: invitation[history_statuses][0][created_by]: Admin invitation[history_statuses][0][site_created_by]: System invitation[sites][0][site]: www.vadaraquartz.com invitation[sites][0][status]: Submitted invitation[sites][0][created]: 2023-08-08 02:27:49 invitation[sites][0][created_by]: Admin invitation[sites][0][id]: 3573 invitation[sites][0][invitation_id]: 3554 invitation[installed_displays]: true invitation[individual_samples]: false invitation[slab_on_displays]: false invitation[type_id]: 1 website: http://site "; // Разбиваем текст на строки $lines = explode("\n", $text); // Функция для преобразования ключей function transformKey($key) { $parts = explode(':', $key); $newKeyParts = array_map(function($part) { return "[$part]"; }, $parts); return implode('', $newKeyParts); } // Преобразование текста и вывод foreach ($lines as $line) { list($key, $value) = explode(':', $line, 2); if(empty($key,$value)){ continue; } $formattedKey = transformKey(trim($key)); $formattedValue = trim($value); echo "$formattedKey: $formattedValue\n"; } ?>
Show:  
Copy Clear