Location: PHPKode > projects > ATUIN > atuin/app/models/rdfengine/Translator.php
<?php

/**
 * provides functions for encoding and decoding
 * special characters in strings. thus i.e. html contents
 * that were stored, using the RDF document model, can
 * be processed by the RDF parser without causing a
 * crash.  
 *
 * @author Michael Lessnau
 * @version 0.1
 */
class Translator {

   /**
    * converts special chars to a form accepted by
    * the DOM API.
    *
    * @param $input string string
    * @return string encoded string
    */
   public function encode( $input) {
      $res = $input;
      $res = str_replace( '<', '&lt;', $res);
      $res = str_replace( '>', '&gt;', $res);
      $res = str_replace( '"', '&quot;', $res);
      $res = str_replace( "\'", "'", $res);
      $res = str_replace( '\"', '"', $res);
      $res = str_replace( '&', '&amp;', $res);
      return $res;
   }

   /**
    * reconverts special chars out of a form accepted
    * by the DOM API.
    *
    * @param $input string string
    * @return string decoded string
    */
   public function decode( $input) {
      $res = $input;
      $res = str_replace( '&amp;', '&', $res);
      $res = str_replace( '&lt;', '<', $res);
      $res = str_replace( '&gt;', '>', $res);
      $res = str_replace( '&quot;', '"', $res);
      $res = str_replace( "\'", "'", $res);
      $res = str_replace( '\"', '"', $res);
      return $res;
   }

};

?>
Return current item: ATUIN