2013-02-15 42 views
0

我有代碼如何在輸入中輸出引號的值?

$name = 'Test world \"Example\" end'; 
<input type="text" name="text" value="'.$name.'"> 

但在輸入頁面上輸入我只看到Test world \

在furebug我看到在輸入全碼:

<input type="text" name="text" value="Test world "Example" end"> 

在結果我看到的報價接近早於必要的。

請告訴我如何做出正確的結果(結果應該與報價)?

+0

htmlencode/htmlspecialchars – Popnoodles 2013-02-15 21:21:27

+1

爲什麼你使用「不只是」?因爲您使用單一配額',那麼不需要轉義雙配額 – 2013-02-15 21:21:37

+1

或者只需使用'"',它將爲您輸出報價。 – Aborted 2013-02-15 21:23:49

回答

1
$name = 'Test world \"Example\" end'; 
echo '<input type="text" name="text" value="'.htmlspecialchars($name,ENT_QUOTES).'">'; 
+0

以及如何刪除'斜槓'? – 2013-02-15 21:59:34

+0

stripslashes($ name); – 2013-02-15 22:14:13

-1

$name = 'Test world \\"Example\\" end'; <input type="text" name="text" value="'.$name.'">

要麼,或編碼這些斜線。