Answer the question
In order to leave comments, you need to log in
How to parse link and meta using phpquery?
Hello. I work with phpquery , there is a task to parse canonical and meta robots
<link rel="canonical" href="site.com" />
<meta name="robots" content="noindex, follow">
function get_content($url){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
$url = "site.com";
$url = get_content($url);
$pQQ = phpQuery::newDocument($url);
$title = pq( 'link' );
foreach ($title as $par) {
$link = pq($par);
echo $link->text().'<br>';
}
Answer the question
In order to leave comments, you need to log in
1. Why reinvent the wheel with get_contents? There is also file_get_contents
2. You need to specify not the domain, but the URL (it starts with http)
3. Using the same $url variable for both the address and the content is a bad idea
4. Look for link and meta in $pQQ['head']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question