php - fn:string function for web content -
i want scrap webpage's content, did, problem is, can't accurate link text, if there kid tag in link text. example, xquery "//div[@class='someclass']/div/a/text()"
, gets accurate result if link somethings <a href='somelink'> link </a>
, (my output :: this link) if link : <a href='somelink'> <br /> text </a>
, output this is, another text because of kid tag br, google, may got solution, solution may fn:string(), can't figure out how can utilize fn:string() in xquery/xpath in php
you didn't show html code. guess html code looking :
<div class='someclass'> <div class='otherclass'> <a href='somelink'> text including kid element <a> </div> </div>
you can seek given below ::
//div[@class='someclass']/div/*
it give info within otherclass div, if tried given below, may problem beingness solved:
<?php $linkquery = $xpath->query("//div[@class='someclass']/div/*"); $linktext = array(); for($i=0, $len = ($linkquery->length) ? $linkquery->length : -1; $i < $len; $i++ ) { $linktext[] = ( $linkquery->item($i) != null ) ? preg_replace('/\s+/', ' ', $linkquery->item($i)->nodevalue ) : 'some default text'; } ?>
now text within link text.
php xpath xquery
No comments:
Post a Comment