2012-12-14 28 views
-1

有誰知道我可以使用如何使用 '' 在PHP

$utf8string = str_replace('\',"\",$utf8string); 

在PHP? 因爲我不能\後使用「,其給我一個錯誤
,如果我寫

$utf8string = str_replace('\ ',"\",$utf8string); 

它不是做我想做

$utf8string = str_replace("\","\",$utf8string); 

不是工作太
等什麼我必須這樣做?
我想更新MySQL,但如果我的文字到底有\其無法正常工作,並給我一個錯誤
這樣的查詢

update phpfox_comment_text set text_parsed = 'nakheir\',text = '' where comment_id = 197597 

有400.000查詢我想更新,但我必須\的Cuz替換\我總是得到這個錯誤

+1

http://php.net/manual /en/language.types.string.php。我覺得有義務告訴你,你有一個很大的SQL注入漏洞,可能使用了不推薦使用的'mysql_'擴展,並且你應該使用PDO或MySQLi和參數化查詢。 – Ryan

+0

感謝您的信息 –

回答

3

嘗試使用\\而不是僅僅\

A \在字符串中具有特殊含義,因爲它用於轉義。意思是一個文字\你需要逃避它!通過前面的一個井,井\

+1

+1是第一個!:P – Eric

+0

該死的速度如此之快,你現在讓我的生活變得輕鬆:D謝謝 –

1

將另一個\\換算。

$utf8string = str_replace("\\","\",$utf8string); 
1

「\」 是「元字符。

如果你願意,你可以在 「使用"\\"逃離」 了。