2017-08-09 63 views

回答

0

preg_replace()通話將做的工作。我的模式和替換將匹配整個字符串,並將其替換爲第一個和第二個捕獲組,它們將通過\連接在一起。

代碼:(PHP Demo

$input='(GMT+07:00) Indian, Christmas'; 
echo preg_replace('/\S+ ([^,]+), (.+)/','$1\\\$2','(GMT+07:00) Indian, Christmas'); 
// output: Indian\Christmas 

這裏是Pattern Demo


這可以有多種方式。如果您使用的是非正則表達式方法,則可以利用每個字符串前面的靜態長度:

echo str_replace(', ','\\',substr($input,12)); // same output 
0

你可以試試這個:1)空字符串""更換()之間的日期,2)更換,\

$string = '(GMT+07:00) Indian, Christmas'; 
$string = preg_replace("/\([^)]+\)/","",$string);// 'Indian, Christmas' 
$string = preg_replace("/\, +\)/","\\",$string);// 'Indian\Christmas'