ampersand character

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
garry27
Forum Commoner
Posts: 90
Joined: Sat Oct 14, 2006 1:50 pm

ampersand character

Post by garry27 »

i'm trying to condense the following code:

Code: Select all

$dj = $_GET['dj'];
  $liveMusic = $_GET['liveMusic'];
  $nsArea = $_GET['nsArea'];
  $food = $_GET['food'];
  $skySport = $_GET['skySport'];
  $cocktails = $_GET['cocktails'];
  $pool = $_GET['pool'];
  $garden = $_GET['garden'];
  $lateLice = $_GET['lateLice'];
  $kidsZone = $_GET['kidsZone'];  
  
  
 
  $query_string = 'dj=' . urlencode($dj) .  '&liveMusic='  . urlencode($liveMusic) 
                . '&kidsZone='  . urlencode($kidsZone) . '&lateLice='  . urlencode($lateLice) 
				. '&nsArea='  . urlencode($nsArea) . '&food='  . urlencode($food) 
				. '&garden='  . urlencode($garden) . '&skySport='  . urlencode($skySport) 
                . '&cocktails='  . urlencode($cocktails) . '&pool=' . urlencode($pool);

into this:

Code: Select all

foreach($_GET as $key=>$value) {
   if ($value !== ''){
    $chkbox_arr[] = '&' . $key .'='. urlencode($key);
   } 
  }  
  $params_str = implode(" ", $chkbox_arr );
  $params_str = substr_replace( $params_str,"",+1 );
but i'm having gaetting the following error with the ampersand when i echo it out to test:

'unexpected '&' in /home/unn_p921847/public_html/test3/create_crawl.php on line 27'

can anyone tell me how to fix this?

TIA
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: ampersand character

Post by volka »

No such parse error in
garry27 wrote:foreach($_GET as $key=>$value) {
if ($value !== ''){
$chkbox_arr[] = '&' . $key .'='. urlencode($key);
}
}
$params_str = implode(" ", $chkbox_arr );
$params_str = substr_replace( $params_str,"",+1 );
Please post line 1 to 27 of the script.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

better yet, replace all of that with

Code: Select all

echo $_SERVER['QUERY_STRING'];
Post Reply