开发者

urlencode/urldecode problem

I am selecting data from a MySql database and doing the following

echo "<input type=\"text\" name=\"distadd1\" id=\"distadd1\" class=\"textbox\" value=".  urlencode($row['ADD1']). " >";

however the value is being displ开发者_开发百科ayed as follows Department+of+Planning+%26+Development.

how do i remove the + and %26


URL encoding is different than what you want to do it sounds like. Try changing URL encode to htmlentities, which will get rid of the '+' and the &26; but will still protect you from XSS / script injection into your webpages.

Example #1 A htmlentities() example
<?php
$str = "A 'quote' is <b>bold</b>";

// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);

// Outputs: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str, ENT_QUOTES);
?>

From the PHP Manual


Don't add those symbols in the first place. The urlencode() function, as its name suggests, is used to generate URLs. You probably want to use htmlspecialchars().

I tried htmlentities but it just returns the first word of the string.

Your HTML is invalid. You need to use quotes so your attributes can contain spaces. Compare:

<input name=user value=foo bar id=foo>
<input name="user" value="foo bar" id="foo">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜