static public function escapeXmlSpecialChars($string, $isAttribute = false)
    {
        if ($isAttribute === false) {
            $fullSearch = array('"', "'", '<', '>');
            $fullReplace = array('&quot;', '&apos;', '&lt;', '&gt;');
            $string = str_replace('&', '&amp;', $string);
            $string = str_replace($fullSearch, $fullReplace, $string);
            return $string;
        } else {
            $string = str_replace('&', '&amp;', $string);
            $string = str_replace('"', '&quot;', $string);
            return $string;
        }
    }
static public function escapeXmlSpecialChars($string, $isAttribute = false)
    {
        if ($isAttribute === false) {
            $fullSearch = array('"', "'", '<', '>');
            $fullReplace = array('&quot;', '&apos;', '&lt;', '&gt;');
            $string = str_replace('&', '&amp;', $string);
            $string = str_replace($fullSearch, $fullReplace, $string);
            return $string;
        } else {
            $string = str_replace('&', '&amp;', $string);
            $string = str_replace('"', '&quot;', $string);
            return $string;
        }
    }
static public function escapeXmlSpecialChars ( $ string , $ isAttribute = false ) { if ( $ isAttribute === false ) { $ fullSearch = array ( '"' , "'" , '<' , '>' ) ; $ fullReplace = array ( '&quot;' , '&apos;' , '&lt;' , '&gt;' ) ; $ string = str_replace ( '&' , '&amp;' , $ string ) ; $ string = str_replace ( $ fullSearch , $ fullReplace , $ string ) ; return $ string ; } else { $ string = str_replace ( '&' , '&amp;' , $ string ) ; $ string = str_replace ( '"' , '&quot;' , $ string ) ; return $ string ; } }
Escape XML Special characters from a given string.

The list below describe each escaped character and its replacement.

* " --> &quot;
* ' --> &apos;
* < --> &lt;
* > --> $gt;
* & --> &amp;

@param string $string An input string.
@param boolean $isAttribute Whether or not to escape ', >, < which do not have to be escaped in attributes.
@return string An escaped string.
Escape XML Special characters from a given string .