note 111036 added to function.ord
| From: | oskar dot mothander at gmail dot com | Date: | Tue, 08 Jan 2013 16:48:56 +0000 |
| Subject: | note 111036 added to function.ord | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192844@lists.php.net to get a copy of this message | ||
I needed to transform some UTF-8 text to ASCII to avoid bots indexing certain material which gave
googling users false hope of finding stuff. However ord() doesn't support UTF-8 and ASCII
doesn't support all UTF-8 chars so I made a neat function that converts all chars to CP437
which is an extended version of ACII that has a wider (but not total) support for UTF-8 chars.
(I'm not sure if google indeed not understand this but past experience tells me so)
<?php
function ascii_encode($str) {
iconv("UTF-8", "CP437", $str);
$encoded = '';
for ($i=0; $i < strlen($str); $i++){
$chr = substr($str,$i, 1);
if (ord($chr) == ord('&')) {
while (ord($chr) != ord(';') && $i < strlen($str)) {
$chr = substr($str,$i, 1);
$i++;
$encoded .= $chr;
}
$i--;
}
else {
$encoded .= '&#'.ord($chr).';';
}
}
return $encoded;
}
?>
----
Server IP: 80.67.0.53
Probable Submitter: 80.216.182.206
----
Manual Page -- http://php.net/manual/en/function.ord.php
Edit -- https://master.php.net/note/edit/111036
Del: integrated -- https://master.php.net/note/delete/111036/integrated
Del: useless -- https://master.php.net/note/delete/111036/useless
Del: bad code -- https://master.php.net/note/delete/111036/bad+code
Del: spam -- https://master.php.net/note/delete/111036/spam
Del: non-english -- https://master.php.net/note/delete/111036/non-english
Del: in docs -- https://master.php.net/note/delete/111036/in+docs
Del: other reasons-- https://master.php.net/note/delete/111036
Reject -- https://master.php.net/note/reject/111036
Search -- https://master.php.net/manage/user-notes.php