0

i have this Download link that will be using a GET method, here's my code:

echo "<a href='dlexcel.php?pname=".s1."&year=".s2."'>DOWNLOAD</a>";

that will be recieve by dlexcel.php

$_GET['pname'].$_GET['year'];

the problem is, s1 is string that can contain the a value &. and the string itself is not complete when $_GET is called.

i already used str_replace and preg_replace but i dont know how to. i need to pull the & out and replace it with something else, i just dont know how or what.

2 Answers 2

3

You need to use

urlencode($s1)

when encoding a string to be used in a query part of a URL

Sign up to request clarification or add additional context in comments.

Comments

1

Try http_build_query(). http://www.php.net/http_build_query

echo '<a href="dlexcel.php?', http_build_query(array(
  'pname' => $s1,
  'year' => $s2
), '">DOWNLOAD</a>');

This takes care of encoding data, while building the entire query string from an array for you, meaning you aren't manually hacking it together. Remember, there is more than just & that you must encode.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.