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.
Link to comment
Share on other sites

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>';
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.