Noticed a bug in my previous solution, which did not take into account spaces followed by semicolon within strings inside sub-queries.
So, here is the updated version. if (!is_array($query)) {
// split string into an array of individual queries
$array = explode(';', $query);
$query = '';
$sub_query = '';
foreach ($array as $value) {
$sub_query .= $value;
if (substr_count(str_replace("\'",'',$sub_query),"'")%2)
{
// Odd number single quotes means semicolon was part of a string in one sub-query
// Must add back the semicolon and loop to restore the remainder of sub-query
$sub_query .= ';';
} // if
else
{
$sub_query = trim($sub_query);
if (!empty($sub_query)) {
$query[] = $sub_query.';'; // replace query terminator
$sub_query = '';
} // if
// $sub_query is empty again ready for the next $value
} // else
} // foreach
} // if