Skip to content

Instantly share code, notes, and snippets.

@igancev
Last active November 25, 2016 10:05
Show Gist options
  • Save igancev/673a1a5ba35f06b3c5c9b8c9ff52a501 to your computer and use it in GitHub Desktop.
Save igancev/673a1a5ba35f06b3c5c9b8c9ff52a501 to your computer and use it in GitHub Desktop.
Подготовка текста перед вставкой его в xml (text2xml)
<?php
class XmlHelper
{
public static function text2xml($text)
{
$text = preg_replace("/[\x1-\x8\xB-\xC\xE-\x1F]/", "", $text);
$text = str_replace('"', '&quot;', $text);
$text = str_replace("&", "&amp;", $text);
$text = str_replace(">", "&gt;", $text);
$text = str_replace("<", "&lt;", $text);
$text = str_replace("'", "&apos;", $text);
return $text;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment