2015-01-21 93 views
-1

我無法與str_replace函數str_replace函數通配符,更換整串

例子:我有一個字符串,說

insert into %table% (%cols%) values (%vals%) 

然後我經過串並嘗試替換每個外卡,但它取代整個字符串。

+2

證明你有試過嗎? – 2015-01-21 06:26:51

回答

0

儘量只在str_replace()

str_replace('%', 'with replace str', $str); // will replace only given char 

通過通配符爲前: -

$str = "insert into %table% (%cols%) values (%vals%)"; 
$newstr = str_replace('%', '', $str); 
echo $newstr; //insert into table (cols) values (vals)