首页 > 解决方案 > 页面上的图像计数器

问题描述

我正在尝试获取当前页面中存在的图像数量。我刚刚找到了一个 JS 方法,但我想通过 php 找到一个方法。如何通过 PHP 获得与此脚本相同的结果?

function myFunction() {
  var x = document.images.length;
  document.getElementById("demo").innerHTML = x;
}

标签: php

解决方案


尝试这个:

<?PHP
$code= file_get_contents($url); //this line is getting HTML code from the website
echo substr_count($code, '<img');
?>

推荐阅读