note 73549 deleted from function.htmlentities by philip
| From: | philip@php.net | Date: | Sat, 03 Mar 2007 20:54:57 +0000 |
| Subject: | note 73549 deleted from function.htmlentities by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-124050@lists.php.net to get a copy of this message | ||
Note Submitter: Rob (www.rob.darwinist.nl)
----
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);
}
}
?>