Jump to content

how to use urlencode( ) in my example?


et4891

Recommended Posts

I checked php.net and read a few examples of how

urlencode( )

works but somehow I just can't get it right. Can someone give me a hand?

 

it'll be a lot to paste everything so hopefully my brief example would make sense.

I have a page called 2.php and it was called to show some contents of a .txt file choosen in 1.php.

I am told to make a link for 3.php and the link should look something like

/3?filename=a.txt with 

filename as GET parameter name and Ensure GET parameter value is urlencoded using the

urlencode( ) function.

 

but I'm confused how and where I should put urlencode() to make it work.

I'll paste my 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…the 3.php option must have a query string appended to it: the name of the text file that was selected in 1, so instead of ./3.php, the url should be something such as .

/3?filename=asdf.txt

 

Use 「filename」 as the GET parameter name. Ensure the GET parameter value is urlencoded using the

urlencode( )

function.

 

but I'm just not sure how to get it to work....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.