2010-05-03 31 views
0

我想「用」更換\但它不會工作的preg_replace不工作的charachter

這是我想從

使用Twitter替換文本\的@Anywhere服務在 6步驟

和這是代碼

$tutorial = "Using Twitter\'s @Anywhere Service in 6 Steps "; 
echo $tutorial."<br /><br />"; 
$tut_title = preg_replace("/\\'/", "'", $tutorial); 
echo $tut_title; 

回答

2

您不需要爲此使用正則表達式。在這種情況下,您可以使用stripslashes

您還可以使用str_replace("\\'", "'", $tutorial);

對於未來的正則表達式的參考,不過,你需要仔細轉義反斜線:

$tut_title = preg_replace("/\\\\'/", "'", $tutorial);

爲什麼?因爲在你當前的表單中,你正在將/\'/傳遞給正則表達式引擎,它只是試圖逃跑'

+0

謝謝你的幫助:) – Christophe 2010-05-03 11:38:23

+0

是的,使用這種方法,雖然由於某種原因,就像它在我最後的回答中一樣。對於那個很抱歉。 – SoLoGHoST 2010-05-03 11:55:30

+0

好的:D謝謝你的幫助 – Christophe 2010-05-03 15:28:50