This is html text in the website, i want to grab
1,000 Places To See Before You Die
<ul class="listings">
<li>
<a href="http://watchseries.eu/serie/1,000_places_to_see_before_you_die" title="1,000 Places To See Before You Die">
1,000 Places To See Before You Die
<span class="epnum">2009</span>
</a>
</li>
I used the code like this
foreach($html->find('ul.listings li a') as $e)
echo $e->innertext. '<br/>';
The output i am getting is like
999: Whats Your Emergency<span class="epnum">2012</span>
including the span pls help me this
You can use
strip_tags()
for thatOr try to use
preg_replace()
to remove unwanted tag and its contentThere are 2 ways that I could think of to solve this. One, is that you grab the title attribute from the anchor tag. Of course, not everyone set up a title attribute for the anchor tag and the value of the attribute could be different if they want to fill it that way. The other solution is that, you get the
innertext
attribute and then replace every child of the anchor tag with an empty value.So, either do this
or this
Though, it might be a good idea to use
DOMDocument
instead for this.Why not
DOMDocument
and get title attribute?:or
Codepad Example
First of all check your html. Now it is like
There is no close tag for ul, perhaps you missed it.
Try like this
Use
plaintext
instead.But still the year will be present which you can trim off using regexp.
Example from the documentation here: