Gumbo PHP Library API Documentation
Converter
[
class tree
] [
index
] [
all elements
]
Todo List
Packages:
Buffer
Collection
Composite
Config
Converter
Curl
Date
DB
Debug
Encryption
Error
Factory
Filter
Flyweight
Http
Input
Iterator
List
Load
Lockable
Log
Map
Number
Observer
Output
Query
Record
Router
Session
Setting
Singleton
Template
Timer
Utility
Valid
Source for file NewLineBreak.class.php
Documentation is available at
NewLineBreak.class.php
<?php
/**
* Gumbo Library Framework
*
* LICENSE
* This library is being released under the terms of the New BSD License. A
* copy of the license is packaged with the software (LICENSE.txt). If no
* copy is found, a copy of the license template can be found at:
* http://www.opensource.org/licenses/bsd-license.php
*
*
@category
Gumbo
*
@package
Converter
*
@copyright
Copyright (c) 2007, iBayou, Michael Luster
*
@license
http://www.opensource.org/licenses/bsd-license.php New BSD License
*
@author
Michael Luster <mluster79@yahoo.com>
*
@link
http://sourceforge.net/projects/phpgumbo
*
@version
0.0.1
*/
/**
* New Line to BR Converter Class
*
*
@category
Gumbo
*
@package
Converter
*
@copyright
Copyright (c) 2007, iBayou, Michael Luster
*
@license
http://www.opensource.org/licenses/bsd-license.php New BSD License
*
@author
Michael Luster <mluster79@yahoo.com>
*
@link
http://sourceforge.net/projects/phpgumbo
*
@desc
New Line to BR Converter Class
*
@version
0.0.1
*/
gumbo_load
(
"Converter_Abstract"
)
;
class
Gumbo_Converter_NewLineBreak
extends
Gumbo_Converter_Abstract
{
/**
@var
string
$_eol
End of Line Characters */
private
$_eol
=
PHP_EOL
;
/**
* Constructor
*
@param
string
$eol
End of Line characters
*/
public
function
__construct
(
$eol
=
null
)
{
if
(
!
is_null
(
$eol
))
{
$this
->
setEOL
(
$eol
)
;
}
}
/** ACTION METHODS **/
/**
* Returns BR tags to New Line Characters
*
@param
string
$data
*
@return
string
*/
public
function
toNl
(
$data
)
{
try
{
// verify precondition
if
(
!
is_string
(
$data
))
{
throw
new
Gumbo_Exception
(
"
Invalid
Argument
'
data
:
str
' => {
$data
}
:
"
.
gettype
(
$data
))
;
}
$txt
=
str_ireplace
(
"<br>"
,
$this
->
getEOL
(
)
,
$data
)
;
$txt
=
str_ireplace
(
"<br/>"
,
$this
->
getEOL
(
)
,
$data
)
;
return
str_ireplace
(
"<br />"
,
$this
->
getEOL
(
)
,
$data
)
;
}
catch
(
Gumbo_Exception
$e
)
{
$e
->
setFunction
(
__METHOD__
)
;
gumbo_trigger
(
$e
)
;
}
return
null
;
}
/**
* Returns New Line Characters to BR tags
*
@param
string
$data
*
@return
string
*/
public
function
toBr
(
$data
)
{
try
{
// verify precondition
if
(
!
is_string
(
$data
))
{
throw
new
Gumbo_Exception
(
"
Invalid
Argument
'
data
:
str
' => {
$data
}
:
"
.
gettype
(
$data
))
;
}
return
str_replace
(
"\n"
,
"<br />"
,
str_replace
(
"\r"
,
""
,
$data
))
;
}
catch
(
Gumbo_Exception
$e
)
{
$e
->
setFunction
(
__METHOD__
)
;
gumbo_trigger
(
$e
)
;
}
return
null
;
}
/** MUTATOR METHODS **/
/**
* Sets the End Of Line Characters
*
@param
string
$eol
*
@throws
Gumbo_Exception
*/
public
function
setEOL
(
$eol
)
{
try
{
// verify precondition
if
(
!
is_string
(
$eol
))
{
throw
new
Gumbo_Exception
(
"
Invalid
Argument
'
eol
:
str
' => {
$eol
}
:
"
.
gettype
(
$eol
))
;
}
$this
->
_eol
=
$eol
;
}
catch
(
Gumbo_Exception
$e
)
{
$e
->
setFunction
(
__METHOD__
)
;
gumbo_trigger
(
$e
)
;
}
}
/** ACCESSOR METHODS **/
/**
* Returns the End of Line characters
*
@return
string
*/
public
function
getEOL
(
)
{
return
$this
->
_eol
;
}
}
?>