PDA

View Full Version : htmlentities function not working



jc_gmk
11-01-2007, 03:01 PM
I am pulling information from a MySQL database and trying to change characters into html characters only it's not working, any ideas?

Here's an example of the code:



$query = "SELECT * FROM mytable WHERE something='something'";
$result = mysql_query($query) or die(mysql_error());

while ($info = mysql_fetch_array($result))
{
print htmlentities($info['somedata']) . "<br>";
}

If one of the values returned is "something & something" it won't change it to "somthing &amp; something"
-----------------
I want to use the result of "$info['somedata']" in a url
e.g.


http://somthing.com?somthing=something%20&amp;%20something

and not


http://somthing.com?something=something & something

only if I use $GET['something'];
it only gets the value "something" not "something & something".

Hope this makes sense!

Twey
11-01-2007, 05:32 PM
That's because you don't want it to become &amp;, you want it to become %26. See urlencode (http://www.php.net/urlencode)().