Jump to content

[SOLVED] myVar that includes "spaces" isn't parsed properly with $_GET['myVar']


scorplev

Recommended Posts

$path = "images/gallery/";
$folders = opendir($path);
while (($folder = readdir($folders)) !== false) {
$foldersArray[] = $folder;
}
for($i=0;$i<sizeof($foldersArray);$i++)
{
echo "<a href=index.php?dir=$foldersArray[$i])>$foldersArray[$i]</a>";
}

 

that works fine when folder name doesn't include spaces.

But when a folder contains space the following output:

 

<a href=index.php?dir=Name>Name Of Folder</a>

 

and not:

<a href=index.php?dir=Name Of Folder>Name Of Folder</a>

 

 

Theres a function called urlencode that will fix that for you. Just bare in mind you will probably need to use urldecode on the other end.

 

<?php
echo '<a href=index.php?dir="'. urlencode($foldersArray[$i]) . '">' . $foldersArray[$i] . '</a>';
?>

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.