Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the span tag value using php curl and simple html dom parser?the exact value does not show

code for this:

  <span class="file-count-label" ng-init="totalResultCount=304575" ng-show="totalResultCount" style="">304,575</span>

$videos=$html->find('span[class=file-count-label]');
foreach($videos as $e)
{
  echo $e->plaintext;
}

output:{{totalResultCount | number}} but i want 304,575

like image 432
Jalis Mahamud Avatar asked Jan 29 '26 16:01

Jalis Mahamud


1 Answers

You can use xpath selector

<?php

$html = '<span class="file-count-label" ng-init="totalResultCount=304575" ng-show="totalResultCount" style="">304,575</span>';
$doc = new DOMDocument;
$doc->loadHTML($html);
$finder = new DomXPath($doc);
$classname="file-count-label";
$videos = $finder->query("//*[contains(@class, '$classname')]");

foreach($videos as $e)
{
  echo $e->nodeValue;
}

Output:- https://eval.in/1056186

Reference taken:- https://stackoverflow.com/a/6366390/4248328

like image 130
Anant Kumar Singh Avatar answered Feb 01 '26 05:02

Anant Kumar Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!