From: Martin G. <gim...@gi...> - 2003-02-25 18:55:34
|
Jeff Dairiki <da...@da...> writes: > There's a problem with using urlencoding to generate filenames for > HTML output. That's because: how do you link to filenames with '%'s > in them? Well ... it depends on whether you're going through a > webserver, or just getting the files off of local disk. > > I think the answer is to switch to some other encoding scheme for > filenames (probably of our own devising). That would get around the > '/' in filenames problem too. How about using quoted-printable? That's a standard for of encoding, but it's not used in URLs (it's used in MIME in mails) so the webserver won't decode it for us. This function encodes everything outside the alphanumeric ASCII characters as quoted-printable and then uses the builtin PHP function quoted_printable_decode() to see if the input matches the output: <?php function quoted_printable_encode($str) { $output =3D ''; $length =3D strlen($str); =20=20 for ($i =3D 0; $i < $length; $i++) { $char =3D $str[$i]; if (ereg('[a-zA-Z ]', $char)) { $output .=3D $char; } else { $output .=3D sprintf('=3D%02X', ord($char)); } } =20=20 return $output; } $input =3D '!"#=A4%&/()=3D?`|+^\'*=E6=F8=E5=E9=E8=E4=F1'; $qp =3D quoted_printable_encode($input); $output =3D quoted_printable_decode($qp); echo "Input: $input\n"; echo "QP: $qp\n"; echo "Output: $output\n"; if ($input =3D=3D=3D $output) { echo "Match\n"; } else { echo "Mismatch!\n"; } ?> With the quoted-printable encoding you're allowed to encode everything, or to leave some printable characters untouched (that's what makes this encoding 'printable' --- it can be decoded by humans), see Section 6.7 in RFC 2045: http://www.ietf.org/rfc/rfc2045.txt > Anyhoo, I'm probably not going to get to looking at it for a bit. > If someone else wants to take a crack at it, feel free. It's important for me to be able to dump a WikiWikiWeb as XHTML, as I'm going to use PhpWiki as a site generation tool. So I'll probably have a look at it... --=20 Martin Geisler My GnuPG Key: 0xF7F6B57B See http://gimpster.com/ and http://phpweather.net/ for: PHP Weather =3D> Shows the current weather on your webpage and PHP Shell =3D> A telnet-connection (almost :-) in a PHP page. |