<?php
$data = <<<DOM
<div class="container">
<div class="catalog-list">
<div class="sub">
<div class="item"></div>
</div>
<div class="item"></div>
<div class="item"></div>
<div class="item" data-type="2"></div>
</div>
</div>
DOM;
$xml = new SimpleXMLElement($data);
$catalogListNodes = $xml->xpath('//*[@class="catalog-list"]/*');
$itemInSubNodes = $xml->xpath('//*[@class="sub"]/*[@class="item"]');
$in = '...your text...';
// never use "e"
$bad = preg_replace('/\&\#([0-9]+)\;/me', "((\\1>255)?(utf8_decode(code2utf(\\1))):('&#\\1;'))", $in);
// use callback instead
$good = preg_replace_callback(
'/\&\#([0-9]+)\;/m',
function ($m) {
if ($m[1] > 255) {
return utf8_decode(code2utf($m[1]));
}
return "&#${m[1]};";
},
$in
);