jyushinx Posted December 12, 2006 Share Posted December 12, 2006 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 &. So when I print out the new link it reads something like: <a href="products.php?class=2&page=2"> Is PHP doing this during the str_replace or when it prints? How can I stop this from happening?Thanks. Quote Link to comment Share on other sites More sharing options...
simcoweb Posted December 12, 2006 Share Posted December 12, 2006 Can you post the code, please? Quote Link to comment Share on other sites More sharing options...
jyushinx Posted December 12, 2006 Author Share Posted December 12, 2006 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>'; Quote Link to comment Share on other sites More sharing options...
448191 Posted December 12, 2006 Share Posted December 12, 2006 Why would you want to replace VALID xhtml with non-valid xhtml? ;) Quote Link to comment Share on other sites More sharing options...
jyushinx Posted December 12, 2006 Author Share Posted December 12, 2006 What exactly do you mean by that? Quote Link to comment Share on other sites More sharing options...
448191 Posted December 12, 2006 Share Posted December 12, 2006 Xhtml has "enitities" to refer to certain characters. All entities start with an ampersand. The ampersand itself is represented by "&"Invalid xhtml:<a href="products.php?class=2&page=2">Valid xhtml:<a href="products.php?class=2&page=2">http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references Quote Link to comment Share on other sites More sharing options...
jyushinx Posted December 12, 2006 Author Share Posted December 12, 2006 Hmmm. So I was the problem, not PHP :)Thanks for your explanation. I appreciate it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.