/** * Tests the static utf8ord method. */ public function test_utf8ord() { $this->assertSame(ord(''), core_text::utf8ord('')); $this->assertSame(ord('f'), core_text::utf8ord('f')); $this->assertSame(0x3b1, core_text::utf8ord('α')); $this->assertSame(0x439, core_text::utf8ord('й')); $this->assertSame(0x2fa1f, core_text::utf8ord('')); $this->assertSame(381, core_text::utf8ord('Ž')); }
/** * This function takes some text and replaces about half of the characters * with HTML entity equivalents. Return string is obviously longer. * * @param string $plaintext The text to be obfuscated * @return string The obfuscated text */ function obfuscate_text($plaintext) { $i = 0; $length = core_text::strlen($plaintext); $obfuscated = ''; $prevobfuscated = false; while ($i < $length) { $char = core_text::substr($plaintext, $i, 1); $ord = core_text::utf8ord($char); $numerical = $ord >= ord('0') && $ord <= ord('9'); if ($prevobfuscated and $numerical) { $obfuscated .= '&#' . $ord . ';'; } else { if (rand(0, 2)) { $obfuscated .= '&#' . $ord . ';'; $prevobfuscated = true; } else { $obfuscated .= $char; $prevobfuscated = false; } } $i++; } return $obfuscated; }
protected function yy_advance() { if ($this->yy_buffer_index < $this->yy_buffer_read) { $char = $this->yy_buffer[$this->yy_buffer_index++]; return core_text::utf8ord($char); } if ($this->yy_buffer_start != 0) { // Shunt. $j = $this->yy_buffer_read - $this->yy_buffer_start; $this->yy_buffer = $this->yy_buffer->substring($this->yy_buffer_start, $j); $this->yy_buffer_end -= $this->yy_buffer_start; $this->yy_buffer_start = 0; $this->yy_buffer_read = $j; $this->yy_buffer_index = $j; $data = fread($this->yy_reader, 8192); if ($data === false || !core_text::strlen($data)) { return $this->YY_EOF; } $this->yy_buffer->concatenate($data); $this->yy_buffer_read += core_text::strlen($data); } while ($this->yy_buffer_index >= $this->yy_buffer_read) { $data = fread($this->yy_reader, 8192); if ($data === false || !core_text::strlen($data)) { return $this->YY_EOF; } $this->yy_buffer->concatenate($data); $this->yy_buffer_read += core_text::strlen($data); } $char = $this->yy_buffer[$this->yy_buffer_index++]; return core_text::utf8ord($char); }