0

in this variable: $this->item->text I have this string:

<!-- 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>

So with this code I extract

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

Code (I am using this library called phpQuery http://code.google.com/p/phpquery/w/list?can=2&q=pq&colspec=PageName+Summary+Changed+ChangedBy):

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

So my question is: How can I remove $extraction string from $this->item->text? Thank you.

1

1 Answer 1

1

I'll assume phpQuery is some library aiding with dom-parsing in php?

Anyway, to accomplish this, you don't exactly need this external library. It can easily be accomplished with a regular expression replace:

$text = preg_replace('/<span.*?class="[^"]*?easy_img_caption[^"]*?".*?>.*?<\/span>/s', '', $this->item->text);
echo "<textarea>" . $text . "</textarea>";
Sign up to request clarification or add additional context in comments.

5 Comments

How have you build the regex expression? Does it exist some tools?
Thought you wanted to remove this span out of the entire string. To actually fetch only that string, use the same regex, but with function preg_match (rather than preg_replace)
mlitn If I want to remove <a class="jwDisqusListingCounterLink" .... how can I do the regex?
preg_replace('/<a.*?class="[^"]*?jwDisqusListingCounterLink[^"]*?".*?>.*?<\/a>/s', '', $this->item->text);
With this string codepad.org/UyxD7qgP your regex delete wrong span...why?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.