opensrs\Ops::_quoteXMLChars PHP Метод

_quoteXMLChars() публичный Метод

Quotes special XML characters.
public _quoteXMLChars ( $string ) : string
Результат string quoted string
    public function _quoteXMLChars($string)
    {
        $search = array('&', '<', '>', "'", '"');
        $replace = array('&amp;', '&lt;', '&gt;', '&apos;', '&quot;');
        $string = str_replace($search, $replace, $string);
        $string = utf8_encode($string);
        return $string;
    }

Usage Example

Пример #1
0
 /**
  * Should convert specials chars, & encode in utf8.
  */
 public function testQuoteXMLChars()
 {
     $ops = new Ops();
     $data = 'This is my & < > \' " string';
     $result = $ops->_quoteXMLChars($data);
     /// chars should be converted
     $this->assertEquals($result, 'This is my &amp; &lt; &gt; &apos; &quot; string');
     // should be utf8
     $this->assertTrue(mb_check_encoding($result, 'UTF-8'));
 }