Automatically add slash to urlencoded urls
I am very confused about the following:
echo("<a href='http://".urlencode("www.test.com/test.php?x=1&y=2")."'>test</a><br>");
echo("<a href='http://"."www.test.com/test.php?x=1&y=2"."'>test</a>");
The first link adds a trailing slash (which causes me problems) The second link does not work.
Can someone help me understand why. Obviously this is similar to urlencode, but I can't figure that out.
Thanks with
You should not use urlencode()echo URLs unless they contain some non-standard characters.
The above example does not contain anything unusual.
Example
$query = 'hello how are you?';
echo 'http://example.com/?q=' . urlencode($query);
// Ouputs http://example.com/?q=hello+how+are+you%3F
, , $query , .. , , . index.php?page=1.
, , , echo 'd.
, , ,
<a href='http://www.test.com%2Ftest.php%3Fx%3D1%26y%3D2'>test</a>