?php / * Define our filter class * / class rot13_filter extends php_user_filter {function read($length) {$tempstr = parent::read($length); for($i = 0; $i strlen($tempstr); $i++) if (($tempstr[$i] = 'A 'AND $tempstr[$i] = 'M') OR ($tempstr[$i] = 'a' AND $tempstr[$i] = 'm')) $tempstr[$i] = chr(ord($tempstr[$i]) + 13); else if (($tempstr[$i] = 'N 'AND $tempstr[$i] = 'Z') OR ($tempstr[$i] = 'n' AND $tempstr[$i] = 'z')) $tempstr[$i] = chr(ord($tempstr[$i]) - 13); return $tempstr;} function write($data) {for($i = 0; $i strlen($data); $i++) if (($data[$i] = 'A 'AND $data[$i] = 'M') OR ($data[$i] = 'a' AND $data[$i] = 'm')) $data[$i] = chr(ord($data[$i]) + 13); else if (($data[$i] = 'N 'AND $data[$i] = 'Z') OR ($data[$i] = 'n' AND $data[$i] = 'z')) $data[$i] = chr(ord($data[$i]) - 13); return parent::write($data);}} / * Register our filter with PHP * / stream_register_filter("rot13", "rot13_filter") or die("Failed to register filter"); $fp = fopen("foo-bar.txt", "w"); / * Attach the registered filter to the stream just opened * / stream_filter_append($fp, "rot13"); fwrite($fp, "Line1\n"); fwrite($fp, "Word - 2\n"); fwrite($fp, "Easy As 123\n"); fclose($fp); / * The filter only applies to the $fp stream * so this readfile will read -without - applying * a second pass of rot13 encoding * / readfile("foo-bar.txt"); / * Output * ----- - Yvar1 Jbeq - 2 Rnfl Nf 123 * /?
?php / * Definition de notre classe de filtre * / class rot13_filter extends php_user_filter {function read($length) {$tempstr = parent::read($length); for($i = 0; $i strlen($tempstr); $i++) if (($tempstr[$i] = 'A 'AND $tempstr[$i] = 'M') OR ($tempstr[$i] = 'a' AND $tempstr[$i] = 'm')) $tempstr[$i] = chr(ord($tempstr[$i]) + 13); else if (($tempstr[$i] = 'N 'AND $tempstr[$i] = 'Z') OR ($tempstr[$i] = 'n' AND $tempstr[$i] = 'z')) $tempstr[$i] = chr(ord($tempstr[$i]) - 13); return $tempstr;} function write($data) {for($i = 0; $i strlen($data); $i++) if (($data[$i] = 'A 'AND $data[$i] = 'M') OR ($data[$i] = 'a' AND $data[$i] = 'm')) $data[$i] = chr(ord($data[$i]) + 13); else if (($data[$i] = 'N 'AND $data[$i] = 'Z') OR ($data[$i] = 'n' AND $data[$i] = 'z')) $data[$i] = chr(ord($data[$i]) - 13); return parent::write($data);}} / * Enregistrement du filtre avec PHP * / stream_register_filter("rot13", "rot13_filter") or die("Impossible d'enregistrer le filtre"); $fp = fopen("foo-bar.txt", "w"); / * Liaison du filtre avec le fl ocirc;t * / stream_filter_append($fp, "rot13"); fwrite($fp, "Line1\n"); fwrite($fp, "Word - 2\n"); fwrite($fp, "Easy As 123\n"); fclose($fp); / * Le filtre ne s'applique qu'au fl ocirc;t $fp * ce qui fait que cette lecture se fait sans d eacute;chiffrement * / readfile("foo-bar.txt"); / * affichage * ----- - Yvar1 Jbeq - 2 Rnfl Nf 123 * /?