<\/script>')

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

+3
source share
3 answers

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>
+2

string urlencode ( $str)

, , URL, .

urlencode .

, echo (), echo "<a href='http [...]</a>";

+1

urlencode() ! :

echo 'http://example.com/index.php?some_link='.urlencode('some value containing special chars like whitespace');

, URL- .. URL-.

+1

Source: https://habr.com/ru/post/1767341/


All Articles