2017-07-14 85 views
-2

中的雙引號內使用單引號解決我由於雙引號內的單引號引起錯誤,並且所有內容都位於$ content變量的單引號內。請問這怎麼解決?

$content = ' 

setTimeout("finishAjax('usernameResult', '"+escape(response)+"')", 400); 

'; 
+4

轉義引用 –

+0

$ content =「setTimeout(\」finishAjax('usernameResult','escape(response)')\「,400)」; – Programit

+0

嗨周杰倫,謝謝你的回覆。但是,它仍然在第105行的C:\ xampp \ htdocs \ fm-reg \ register.php中顯示錯誤「Parse error:syntax error,unexpected'usernameResult'(T_STRING);」 – jbm59er

回答

0

爲了在字符串文字中放置單引號或雙引號,必須首先將其轉義。 PHP中的轉義字符是反斜線(\)。

$content = "setTimeout(\"finishAjax('usernameResult', '+escape(response)+')\", 400);"; 

閱讀更多關於轉義字符HERE

相關問題