我正在尝试分解这个字符串,以便它可以在 wordpress 中适合“$wpdb->insert”函数。这是要插入的字符串。该文件包含大约 42k 字符串,如下所示:
(601, 'STANDARD', 'Adjuntas', '', 'Colinas Del Gigante, Jard De Adjuntas, Urb San Joaquin', 'PR', 'Adjuntas', 'America/Puerto_Rico', '787,939', '18.16', '-66.72', 'NA', 'US', 0, 0, ''),
这是代码
if ( file_exists(realpath(dirname(__FILE__)).'/install/usa_zip_codes.sql')){
$filecontent = explode("\n",file_get_contents( realpath(dirname(__FILE__)).'/install/usa_zip_codes.sql'));
foreach( $filecontent as $row){
$array = array();
$array = explode(", ", trim(preg_replace("/[()]/","",$row),","));
$wpdb->insert(
$wpmyplugin_table['yp_usa_zip_codes'],
array(
'zip' => $array[0],
'type' => trim($array[1],"'"),
'primary_city' => trim($array[2],"'"),
'acceptable_cities' => trim($array[3],"'"),
'unacceptable_cities' => trim($array[4],"'"),
'state' => trim($array[5],"'"),
....
但是当我有像'Colinas Del Gigante, Jard De Adjuntas, Urb San Joaquin'这样的字符串时,它也会将其拆分为数组元素。我试图爆炸,explode(", '",
但这部分, 0, 0, ''不会被正确分割。你如何处理这些事情?