I checked php.netand read some examples of how it works urlencode( ), but for some reason I just can't get it right. Can someone give me a hand?
It will be a lot, for example, so hopefully my brief example will make sense.
I have a page with a name 2.php, and it is called to display some of the contents of the file .txtselected in 1.php.
I was told to make a link for 3.php, and the link should look something like /3?filename=a.txt
with the file name as the parameter name GETand the parameter value GET urlencodedusing the function urlencode( ).
but I am confused how and where should I put urlencode()it to work.
I embed 2.php code here ... I simplified the codes a bit ...
<?php
$fileContents = file("./aaa/" . $_GET["course"] . ".txt");
echo "<table border=\"1\">";
foreach($fileContents as $row)
{
echo "<tr>";
$contents = preg_split("/,/", $row);
foreach($contents as $eachline)
{
echo "<td>";
if(!(preg_match("/@/", $eachline)))
{
echo trim(ucfirst($eachline));
}
else
{
echo trim(strtolower($eachline));
}
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
echo "<a href='./1.php'>Choose another txt file</a><br/>";
echo "or<br/>";
echo "<a href='.3.php?'>Work with this txt file</a>";
?>
BUT ... for the 3.php parameter, a query string should be added: the name of the text file selected in 1, therefore instead. /3.php URL should be something like. / 3? file_name = asdf.txt
Use "file name" as the name of the GET parameter. Verify that the GET parameter value is assigned to urlencoded using the urlencode () function.
but I'm just not sure how to make it work.
source
share