Hi, Guest ~ Login or Register

Fixing the ampersand problem in PHP

Fixing the ampersand problem in PHP

Listed In PHP and MySQL » General Development — Viewing Full Tutorial
Ok, this short tutorial is very important for valid PHP documents with advanced navigation and/or that use sessions.

Sessions are very useful until you start trying to code valid HTML or XHTML with PHP in them. You'll notice on all your links, PHP adds on PHPSESSID to the end, e.g. if you had something like:<a href="yourpage.php">Click Here!</a>
After PHP parsed it, it would become:<br />
<a href="yourpage.php?PHPSESSID=23487347612afb34234234h">Click Here!</a>&lt;br /&gt;
Of course, this would be harmless to your valid document until you had an advanced navigation system, where you can't have 2 ?'s in the url and instead you have an ampersand (&).
For example:
&lt;a href=&quot;?area=main&amp;page=blah&quot;&gt;Blah&lt;/a&gt; is not valid, because the encoding would think that there is such HTML special charachter as &amp;page=blah; and the W3C validator wouldn&#039;t like it.. &lt;br /&gt;
&lt;br /&gt;
You first of all change all &amp;&#039;s to &amp; (you could use find and replace if you have been graced with Dreamweaver) and second of all, on top of all your main PHP file (in avengex.com&#039;s case it&#039;s index.php because it includes stuff) add this code:&lt;br /&gt;
&lt;? ini_set(&quot;arg_separator.output&quot;, &quot;&amp;&quot;); ?&gt;&lt;br /&gt;
&lt;br /&gt;
Basically what this does is changes &amp; to &amp; - this has no effect on the URL but simply makes your document valid. You can be assured that this works if you click the XHTML valid button down the bottom right of the site where the buttons are!&lt;br /&gt;
&lt;br /&gt;
Anyway if you have any questions just comment.&lt;br /&gt;
&lt;br /&gt;
Will

Working Beta

  1. The Forums
    These are mostly functional. If you see any weird bugs, post a thread about it and an administrator will do something.
  2. Tutorial Writing
    You can now submit tutorials to the brand new management system.
  3. Tutorials Home
    View tutorials by categories and search for them here.
  4. Shoutbox
    See below. Registered users only!

Register

Newest User

Say hi to Lirette25! Lirette25 joined on Monday, 14th July.

Sponsor

Check out Next day fake id

Shoutbox