Source for file NewLineBreak.class.php

Documentation is available at NewLineBreak.class.php

  1. <?php
  2. /**
  3.  * Gumbo Library Framework
  4.  *
  5.  * LICENSE
  6.  * This library is being released under the terms of the New BSD License.  A
  7.  * copy of the license is packaged with the software (LICENSE.txt).  If no
  8.  * copy is found, a copy of the license template can be found at:
  9.  * http://www.opensource.org/licenses/bsd-license.php
  10.  * 
  11.  * @category Gumbo
  12.  * @package Converter
  13.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  14.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  15.  * @author Michael Luster <mluster79@yahoo.com>
  16.  * @link http://sourceforge.net/projects/phpgumbo
  17.  * @version 0.0.1
  18.  */
  19.  
  20. /**
  21.  * New Line to BR Converter Class
  22.  *
  23.  * @category Gumbo
  24.  * @package Converter
  25.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  26.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  27.  * @author Michael Luster <mluster79@yahoo.com>
  28.  * @link http://sourceforge.net/projects/phpgumbo
  29.  * @desc New Line to BR Converter Class
  30.  * @version 0.0.1
  31.  */
  32.  
  33. gumbo_load ("Converter_Abstract");
  34.  
  35.     
  36.     /** @var string $_eol End of Line Characters */
  37.     private $_eol = PHP_EOL;
  38.     
  39.     
  40.     
  41.     /**
  42.      * Constructor
  43.      * @param string $eol End of Line characters
  44.      */
  45.     public function __construct ($eol=null{
  46.         if (!is_null ($eol)) $this->setEOL ($eol)}
  47.     }
  48.     
  49.     
  50.     
  51.     /** ACTION METHODS **/
  52.     /**
  53.      * Returns BR tags to New Line Characters
  54.      * @param string $data 
  55.      * @return string 
  56.      */
  57.     public function toNl ($data{
  58.         try {
  59.             // verify precondition
  60.             if (!is_string ($data)) {
  61.                 throw new Gumbo_Exception ("Invalid Argument 'data:str' => {$data}:gettype ($data));
  62.             }
  63.             
  64.             $txt str_ireplace ("<br>"$this->getEOL ()$data);
  65.             $txt str_ireplace ("<br/>"$this->getEOL ()$data);
  66.             return str_ireplace ("<br />"$this->getEOL ()$data);
  67.         catch (Gumbo_Exception $e{
  68.             $e->setFunction (__METHOD__);
  69.             gumbo_trigger ($e);
  70.         }
  71.         return null;
  72.     }
  73.     
  74.     /**
  75.      * Returns New Line Characters to BR tags
  76.      * @param string $data 
  77.      * @return string 
  78.      */
  79.     public function toBr ($data{
  80.         try {
  81.             // verify precondition
  82.             if (!is_string ($data)) {
  83.                 throw new Gumbo_Exception ("Invalid Argument 'data:str' => {$data}:gettype ($data));
  84.             }
  85.             
  86.             return str_replace ("\n""<br />"str_replace ("\r"""$data));
  87.         catch (Gumbo_Exception $e{
  88.             $e->setFunction (__METHOD__);
  89.             gumbo_trigger ($e);
  90.         }
  91.         return null;
  92.     }
  93.     
  94.     
  95.     
  96.     /** MUTATOR METHODS **/
  97.     /**
  98.      * Sets the End Of Line Characters
  99.      * @param string $eol 
  100.      * @throws Gumbo_Exception
  101.      */
  102.     public function setEOL ($eol{
  103.         try {
  104.             // verify precondition
  105.             if (!is_string ($eol)) {
  106.                 throw new Gumbo_Exception ("Invalid Argument 'eol:str' => {$eol}:gettype ($eol));
  107.             }
  108.             
  109.             $this->_eol = $eol;
  110.         catch (Gumbo_Exception $e{
  111.             $e->setFunction (__METHOD__);
  112.             gumbo_trigger ($e);
  113.         }
  114.     }
  115.     
  116.     
  117.     
  118.     /** ACCESSOR METHODS **/
  119.     /**
  120.      * Returns the End of Line characters
  121.      * @return string 
  122.      */
  123.     public function getEOL ({
  124.         return $this->_eol;
  125.     }
  126.     
  127. }
  128.  
  129. ?>