界别文本中的文字与图片
区分文本中的文字与图片
有段文本如下,我想用php把其中的文字部分弄出来赋值给一个变量,图片描述的部分再区分出来赋值给一个变量,用程序怎么实现?
<p>物品尺寸/规格:高24厘米,,好东西值得收藏。</p><p><img src="/ueditor/php/../../data/attachment/antique//20141123/14167157082579.jpg" style="max-width:700px;width:expression(this.width > 700? 700: true);" title="1.jpg"/></p><p><img src="/ueditor/php/../../data/attachment/antique//20141123/14167157109272.jpg" style="max-width:700px;width:expression(this.width > 700? 700: true);" title="2.jpg"/></p><p><img src="/ueditor/php/../../data/attachment/antique//20141123/14167157112075.jpg" style="max-width:700px;width:expression(this.width > 700? 700: true);" title="3.jpg"/></p><p><br/></p>
------解决思路----------------------
图片描述的部分 是指各个title吗?那就有多个哦。
------解决思路----------------------
$str1是文字描述
$str2是图片描述
------解决思路----------------------
有段文本如下,我想用php把其中的文字部分弄出来赋值给一个变量,图片描述的部分再区分出来赋值给一个变量,用程序怎么实现?
<p>物品尺寸/规格:高24厘米,,好东西值得收藏。</p><p><img src="/ueditor/php/../../data/attachment/antique//20141123/14167157082579.jpg" style="max-width:700px;width:expression(this.width > 700? 700: true);" title="1.jpg"/></p><p><img src="/ueditor/php/../../data/attachment/antique//20141123/14167157109272.jpg" style="max-width:700px;width:expression(this.width > 700? 700: true);" title="2.jpg"/></p><p><img src="/ueditor/php/../../data/attachment/antique//20141123/14167157112075.jpg" style="max-width:700px;width:expression(this.width > 700? 700: true);" title="3.jpg"/></p><p><br/></p>
------解决思路----------------------
图片描述的部分 是指各个title吗?那就有多个哦。
------解决思路----------------------
$str1是文字描述
$str2是图片描述
$content=<<<TXT
<p>物品尺寸/规格:高24厘米,,好东西值得收藏。</p><p><img src="/ueditor/php/../../data/attachment/antique//20141123/14167157082579.jpg" style="max-width:700px;width:expression(this.width > 700? 700: true);" title="1.jpg"/></p><p><img src="/ueditor/php/../../data/attachment/antique//20141123/14167157109272.jpg" style="max-width:700px;width:expression(this.width > 700? 700: true);" title="2.jpg"/></p><p><img src="/ueditor/php/../../data/attachment/antique//20141123/14167157112075.jpg" style="max-width:700px;width:expression(this.width > 700? 700: true);" title="3.jpg"/></p><p><br/></p>
TXT;
$data = explode('</p><p>', $content);
$str1 = $data[0].'</p>';
unset($data[0]);
$str2 = '<p>'.implode('</p><p>', $data);
echo $str1;
echo $str2';
------解决思路----------------------
$s='<p>物品尺寸/规格:高24厘米,,好东西值得收藏。</p><p><img src="/ueditor/php/../../data/attachment/antique//20141123/14167157082579.jpg" style="max-width:700px;width:expression(this.width > 700? 700: true);" title="1.jpg"/></p><p><img src="/ueditor/php/../../data/attachment/antique//20141123/14167157109272.jpg" style="max-width:700px;width:expression(this.width > 700? 700: true);" title="2.jpg"/></p><p><img src="/ueditor/php/../../data/attachment/antique//20141123/14167157112075.jpg" style="max-width:700px;width:expression(this.width > 700? 700: true);" title="3.jpg"/></p><p><br/></p>';
preg_match_all('/[\x7f-\xff]+/',$s,$a);
$s1=implode('',$a[0]);
preg_match_all('/title="(.*?)"/',$s,$b);
echo $s1; //文字部分
print_r($b[1]); //图片描述