Oversætte simpel java til php
Kan du oversætte dette til PHP?[code lang="Java"] public static QStringBuffer encodeString(QStringBuffer qstringbuffer, String s)
{
if(s == null)
return qstringbuffer;
for(int k = 0; k < s.length(); k++)
{
char c = s.charAt(k);
if(c < ' ' || c > '\177' || c == '*' || c == '&' || c == ',' || c == quotechar)
{
qstringbuffer.append('&');
int i = c;
for(int l = 0; l < 4; l++)
{
int j = (i & 0xf000) >> 12;
qstringbuffer.append((char)(65 + j));
i <<= 4;
}
} else
{
qstringbuffer.append(c);
}
}
return qstringbuffer;
}
[/code]
Jeg har selv forsøgt, men det fungere vidst ikke helt optimalt.
[code lang="PHP"]
private function encodeFuck($s) {
$stringbuffer = "32";
for($k = 0; $k < strlen($s); $k++){
$c = $s{$k};
if($c < ' ' || $c > '\177' || $c == '*' || $c == '&' || $c == ',' || $c == "'".chr(0)){
$stringbuffer .= "&";
$i = $c;
for($l = 0; $l < 4; $l++){
$j = ($i & 0xf000) >> 12;
$stringbuffer.= chr(65 + $j);
$i <<= 4;
}
} else {
$stringbuffer.=$c;
}
}
return $stringbuffer;
}[/code]