Prevent ampersands breaking validation | Comments (0)
Posted in Code on 1st June 2004, 10:15 pm by Stuart
When you have toiled to build a site that follows current web standards, it can be a real shame when adding a PHP script you find that validation gets broken.
One particular problem is where PHP functions create urls (addresses) that contain the “&” or ampersand.
To stop this from holding back an otherwise perfectly formed piece of XHTML you can use a little trick to make PHP use the html entity for the ampersand character.
Add the following to your script’s config file or anywhere that it will be included on everypage that creates sessions.
ini_set('arg_separator.ouput', '&');
Now the urls are created using the entity for ampersands and your script will now be compliant with XHTML 1.0.
Now that has got you started you can take into consideration other php.ini over-rides possible with the ini_set() function.
