Hi
Could anyone tell me why the preg_replace function is not working on this script please, it is supposed to put a space after the first 5 digits of a phone number when it has been entered as 01234567890, but it doesn't seem to do anything.
I would appreciate any assistance or suggestions.
Thanks,
Phil
PS I am using php v4.48
$host = 'localhost';
$user = 'username';
$pass = 'password';
$db = 'database_name';
$file = 'export';
$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");
$replace = array(
'address_book_id' => '',
'entry_company' => 'Customer Name',
'entry_firstname' => 'First Name',
'entry_lastname' => 'Last Name',
'entry_street_address' => 'Billing Address1',
'entry_suburb' => 'Billing Address2',
'entry_city' => 'Billing Address3',
'entry_state' => 'Billing Address4',
'entry_postcode' => 'Billing Address5',
'customers_email_address' => 'Email'
);
function split_num($num){
$num = preg_replace("[^0-9]",'',$num);
$s1 = substr($num,0,5);
$s2 = substr($num,5,11);
$num = "$s1 $s2";
return($num);
}
$values = mysql_query("SELECT zen_orders.customers_company, zen_orders.customers_name, zen_orders.customers_street_address, zen_orders.customers_suburb, zen_orders.customers_city, zen_orders.customers_state, zen_orders.customers_postcode, zen_orders.customers_country, zen_orders.customers_telephone, zen_orders.customers_email_address
FROM zen_orders
");
$i=0;
while ($rowr = mysql_fetch_assoc($values)) {
if($i==0) {
$rowr['customers_telephone'] = split_num($rowr['customers_telephone']);
foreach(array_keys($rowr) as $title)
$csv_output .= '"'.str_replace(array_keys($replace), $replace, $title).'",';
$csv_output .= "\n";
}
foreach ($rowr as $key => $value) {
$csv_output .= '"'.$value.'",';
}
$csv_output .= "\n";
$i++;
}
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;