0
$url='%EA%B3%A0%EC%B9%B4%EC%A7%80%EB%85%B8';

echo '<a href="/'.$url.'">'.$url.'</a>';

And it shows the url is: mywebsite.com/고카지노 with anchor:

%EA%B3%A0%EC%B9%B4%EC%A7%80%EB%85%B8

Can you show me how to convert anchor to 고카지노? Thank you very much.

Ban
  • 131
  • 1
  • 2
  • 9

1 Answers1

1

Use urldecode

$url = urldecode('%EA%B3%A0%EC%B9%B4%EC%A7%80%EB%85%B8');
echo "<a href='/$url'>$url</a>";

// Results in:
// <a href="/고카지노">고카지노</a>
ಠ_ಠ
  • 3,060
  • 28
  • 43
  • 1
    Please don't do this without re-encoding the result as HTML. As written, if `$url` is controlled by an attacker, then they can run arbitrary JavaScript, for example by using a value like `%27%20onclick=%27alert%28%29` – Mike Samuel Dec 14 '14 at 04:53
  • @Mike Samuel, hello, I don't quite understand. How to fix it ? – Ban Dec 14 '14 at 05:03
  • @Ban, ["How to prevent XSS with HTML/PHP"](http://stackoverflow.com/questions/1996122/how-to-prevent-xss-with-html-php) has some good answers. – Mike Samuel Dec 14 '14 at 06:37
  • @Mike Samuel, Hello, I used htmlspecialchars_decode but it doesn't work. – Ban Dec 14 '14 at 07:36
  • @Ban, you have a string of URL encoded bytes that you want to embed in HTML. Use `urldecode` to get a string of plain text, then `htmlspecialchars` to get a string of HTML. `$url = htmlspecialchars(urldecode($x))`. – Mike Samuel Dec 14 '14 at 14:48