2011-11-06 83 views
0

HTML代碼在這個變量函數:$ this->用品 - >正文我有這個字符串:[PHP]刪除字符串

<!-- JoomlaWorks "Disqus Comment System for Joomla!" Plugin (v2.2) starts here --> 

<div class="itp-fshare-floating" id="itp-fshare" style="position:fixed; top:30px !important; left:50px !important;"></div><p>Lorem Ipsum è un testo segnaposto utilizzato nel settore della tipografia e della stampa. Lorem Ipsum è considerato il testo segnaposto standard sin dal sedicesimo secolo, quando un anonimo tipografo prese una cassetta di caratteri e li assemblòdei fogli di caratteri trasferibili 「Letraset」,</p> 
<p style="text-align: center;"><span class="easy_img_caption" style="display:inline-block;line-height:0.5;vertical-align:top;background-color:#F2F2F2;text-align:left;width:150px;float:left;margin:0px 10px;"><a href="/joomla/index.php?option=com_content&view=article&id=8:recensione&catid=3:recensione-dei-servizi-di-cloud-computing&Itemid=4"><img src="/joomla/plugins/content/imagesresizecache/8428e9c26f1d8498ece730c0aa6aa023.jpeg" border="0" alt="1" title="1" style="width:150px; height:120px; ;margin:0;" /></a><span class="easy_img_caption_inner" style="display:inline-block;line-height:normal;color:#000000;font-size:8pt;font-weight:normal;font-style:normal;padding:4px 8px;margin:0px;">1</span></span></p> 
<p>che contenevano passaggi del Lorem Ipsum, e più recentemente da software di impaginazione come Aldus PageMaker</p> 

<!-- Disqus comments counter and anchor link --> 
<a class="jwDisqusListingCounterLink" href="http://clouderize.it/joomla/index.php?option=com_content&view=article&id=8:recensione&catid=3:recensione-dei-servizi-di-cloud-computing&Itemid=4#disqus_thread" title="Add a comment"> 
    Add a comment</a> 

<!-- JoomlaWorks "Disqus Comment System for Joomla!" Plugin (v2.2) ends here --> 

<div class="cp_tags"> 
<span class="cp_tag_label">Tags: </span><span class="cp_tag cp_tag_6"><a href="/joomla/index.php?option=com_customproperties&task=tag&tagId=6&Itemid=1">Recensioni</a> 
</span> </div> 
與此代碼

所以我提取

<span class="easy_img_caption......></span> 

代碼(我使用的)這個庫稱爲phpQuery http://goo.gl/rSu3k

include_once('includes/phpQuery.php'); 
$doc = phpQuery::newDocument($this->item->text); 
$extraction=pq('.easy_img_caption:eq(0)')->htmlOuter(); 
echo"<textarea>".$extraction."</textarea>"; 

所以我的問題是: 如何刪除$提取物離子字符串從$ this-> item-> text? 謝謝。

+0

你的問題很不精確。什麼是'phpQuery.php'?它是[PHP的jQuery端口稱爲phpQuery](http://code.google.com/p/phpquery/)? – Tadeck

+0

對不起,我添加它。 – michele

回答

1

我會假設phpQuery是一些庫幫助與dom解析在php中?

無論如何,要做到這一點,你並不完全需要這個外部庫。它可以很容易地用正則表達式來替代:

$text = preg_replace('/<span.*?class="[^"]*?easy_img_caption[^"]*?".*?>.*?<\/span>/s', '', $this->item->text); 
echo "<textarea>" . $text . "</textarea>"; 
+0

但我需要 ...代碼 – michele

+0

你是如何構建正則表達式的?它是否存在一些工具? – michele

+0

以爲你想從整個字符串中刪除這個跨度。 要實際只提取該字符串,使用相同的正則表達式,但與函數preg_match(而不是preg_replace) – matthiasmullie