R.A. Epigonos et al.

Perl - URIエスケープ、アンエスケープはURI::Escapeを使う

URIエスケープする。エスケープする対象は、postの中味だとか、getの?hoge=以降とかそういうもの。

どんな文字列でもエスケープ、アンエスケープすることは出来る。この出力はもしかするとユーザの思い通りに動いていないかもしれない。本来URIエスケープせねばいけない部分を切り出してエスケープしなければいけない。

$ perl -l -MURI::Escape -e 'print URI::Escape::uri_escape("http://www.google.com/search?q=perl");'
http%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dperl
$ perl -l -MURI::Escape -e 'print URI::Escape::uri_unescape("http://www.google.com/search?q=perl+1%E8%A1%8C&num=100");'
http://www.google.com/search?q=perl+1行&num=100

URIエスケープするべき部分を切り出して。

use URI::Escape;
my $unescaped = "日本語";
my $escaped = "";
$escaped   = uri_escape( $unescaped ); #URLエンコード済み文字列へのエンコード
$unescaped = uri_unescape( $escaped ); #URLエンコード済み文字列のデコード

リファレンス

  1. URI::Escape
  2. URI::Escape - 安全でない文字のエスケープとアンエスケープ
  3. perl url encode - Google 検索
  4. メモ:PerlでURLエンコード・デコードはURI::Escapeを使う - hylom の日記

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2008-01-22T09:37:59+09:00
  2. Modified: 2008-01-22T09:37:59+09:00
  3. Generated: 2023-08-27T23:09:10+09:00