eval.in

Paste #10248

PHP — PHP 5.4.6, pasted 1 year ago

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<?php

function xml_entities($string) {
    return strtr(
        $string, 
        array(
            "<" => "&lt;",
            ">" => "&gt;",
            '"' => "&quot;",
            "'" => "&apos;",
            "&" => "&amp;",
        )
    );
}

$text = "Test &amp; <b> and encode </b> :)";
echo xml_entities($text);

Program Output

Test &amp;amp; &lt;b&gt; and encode &lt;/b&gt; :)

OK (0.004 sec real, 0.005 sec wall, 13 MB, 42 syscalls)

Fork