Jump to content

php $_GET doesn't understand "&" how do i validate?


ahs10

Recommended Posts

in my js i had url's like "whatever.php?id=1&var=0"

 

because of the ampersand the html markup wouldn't validate so i used the entity &

 

this broke the php script reading the var with $_GET['var'], i guess php doesn't recognize & as an ampersand?  how do i get my html markup to validate and php to work properly.

 

thanks!

& is not a valid url parameter. you must use & in order for values to be passed.

 

page.php?a=1&b=2&c=3

 

print $_GET['c'];

 

Use php to validate data instead of javascript. If javascript is disabled then your data will never be validated

it should look like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head>
    <title>Test</title>
  </head>
  <body>
    <p><a href="whatever.php?id=1&var=0">Test</a></p>
  </body>
</html>

thanks for the reply guys.

 

rhodesa - that won't work, if this were the contents of whatever.php -

<?php
echo $_GET['var'];
?>

you would have a blank page :(

 

neil - you are correct, i understand the & is not a valid url parameter and php will not recognize it.  i think perhaps i didn't explain myself well though.  i would like to validate my html markup.... with w3c.  i can't figure out how to be able to pass get variables to outside php scripts and still have valid html markup.

 

 

The fact is whatever.php?id=1&var=0 is a valid url. Forget any HTML validator as you are not passing html through urls.

What I would recommend would be to rewrite these urls using mod_rewrite making them search engine friendly.

An example of

/whatever.php?id=1&var=0

/whatever/1/0

um...what browser are you using? and do you have a link to the page so i can see it? cus the following on my page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head>
    <title>Test</title>
  </head>
  <body>
    <p><a href="whatever.php?id=1&var=123">Test</a></p>
  </body>
</html>

and in whatever.php:

<?php
print $_GET['var'];
?>

prints '123' for me

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.