Jump to content

PHP Prints HTML Special Characters..I don't want this!


jyushinx

Recommended Posts

Hi,

I am running into a small problem when I am trying to print HTML with PHP.

I am in the process of paging results from a mySQL database. When the user clicks on a next or previous link, it must retain the current filter criteria when jumping to the next/previous page. I do this by taking the current Query String with $_SERVER['QUERY_STRING'], then calling str_replace, where I replace the page number with the next or previous page, depending on which link I am working with.

This all works well except for one thing. When I run str_replace and create the new link, PHP replaces the & in my query strings with &amp;. So when I print out the new link it reads something like: <a href="products.php?class=2&amp;page=2"> Is PHP doing this during the str_replace or when it prints? How can I stop this from happening?

Thanks.
Here it is ($page is the current page #):

$currentQueryString = $_SERVER['QUERY_STRING'];

$previousPageAddress = str_replace('page='.$page,'page='.($page-1),$currentQueryString);
$previousPageAddress = 'products.php?'.$previousPageAddress;

print '<a href="'.$previousPageAddress.'"><img alt="Previous" src="graphics/page_previous.gif"></a>';
Xhtml has "enitities" to refer to certain characters. All entities start with an ampersand. The ampersand itself is represented by "&amp;"

Invalid xhtml:

<a href="products.php?class=2&page=2">

Valid xhtml:

<a href="products.php?class=2&amp;page=2">

http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.