php / regex: ayrı besleme verileri

2 Cevap php
<description>&lt;img src='http://example.com/Pic_018_70x70.gif'&gt;&lt;/img&gt;&lt;br /&gt;This is the content of the description.</description>

Ben görüntüleri yem açıklama alanına gelen varsa, nasıl bir değişken görüntüyü ayırmak ve gürültü şerit ve açıklaması çok sol olabilir?

2 Cevap

Bu size söz dizeden img src niteliğinin değer vermek ve size metni verecektir:

$sxml = new SimpleXMLElement(html_entity_decode($str));
$images = $sxml->xpath('//@src');
$text = $sxml->xpath('//description');

echo $images[0];  // http://example.com/Pic_018_70x70.gif
echo $text[0];    // This is the content of the description.

Ayrıca kullanabilirsiniz simplexml

$xml = simplexml_load_string($string);
$description = $xml->description;