note 73549 added to function.htmlentities
| From: | (www.rob.darwinist.nl) | Date: | Wed, 28 Feb 2007 21:30:04 +0000 |
| Subject: | note 73549 added to function.htmlentities | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123968@lists.php.net to get a copy of this message | ||
I had to make links to files with special characters in their (iso-8859-1) filenames from a utf-8
page. No combination of htmlentities or utf8_decode/utf8_encode seemed to help, so finally I wrote
this function to get the links to work. Maybe it's useful to someone else as well:
<?php
function MakeURISafe($s, $charset) {
// works only for $charset == 'ISO-8859-1';
global $charhex;
if ($charset == 'ISO-8859-1') {
if (!isset($charhex)) {
$charhex = array();
for ($i=32; $i<256; $i++) {
$charhex[chr($i)] = '%'.strtoupper(dechex($i));
}
}
return strtr($s, $charhex);
}
}
?>
----
Server IP: 83.137.20.120
Probable Submitter: 84.27.238.184
----
Manual Page -- http://www.php.net/manual/en/function.htmlentities.php
Edit -- https://master.php.net/note/edit/73549
Del: integrated -- https://master.php.net/note/delete/73549/integrated
Del: useless -- https://master.php.net/note/delete/73549/useless
Del: bad code -- https://master.php.net/note/delete/73549/bad+code
Del: spam -- https://master.php.net/note/delete/73549/spam
Del: non-english -- https://master.php.net/note/delete/73549/non-english
Del: in docs -- https://master.php.net/note/delete/73549/in+docs
Del: other reasons-- https://master.php.net/note/delete/73549
Reject -- https://master.php.net/note/reject/73549
Search -- https://master.php.net/manage/user-notes.php