Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用条件从html页面获取值_Php_Html - Fatal编程技术网

Php 使用条件从html页面获取值

Php 使用条件从html页面获取值,php,html,Php,Html,我需要php方面的帮助: 想象一下访问链接“”,每次我访问页面上的html结果都不一样: code=0001 refresh the page ... code=1545 refresh the page ... code=7845 .... 我想知道如何将以下代码添加到要在页面大多数位置使用的=符号中从URL生成一个包含10个代码的数组: <?php $codes = array(); for($i = 1; $i<=10; $i++){ $string = file_g

我需要php方面的帮助:

想象一下访问链接“”,每次我访问页面上的html结果都不一样:

code=0001
refresh the page ...
code=1545
refresh the page ...
code=7845
....

我想知道如何将以下代码添加到要在页面大多数位置使用的=符号中

从URL生成一个包含10个代码的数组:

<?php

$codes = array();

for($i = 1; $i<=10; $i++){
  $string = file_get_contents("URLHERE");
  $string = explode('=',$string);
  $code = $string[1];
  $codes[] = $code;
}

?>

用法:
foreach($codes as $code)
 echo $code . "<br />";

echo "First Code: {codes[0]}";
?>
foreach($code作为$code)
echo$代码。“
”; echo“第一个代码:{Code[0]}”; ?>
听起来像是你想击败CAPTCHAUse
文件_get_contents
来获取页面内容,简单的PHP DOM解析器来解析它,然后从适当的元素中提取代码。你应该发布更多关于你想要解析的内容的详细信息。HTTP响应的主体是否只是字面上的
“code=0001”
,或者是否存在HTML标记?你能发布一个你需要解析的页面的例子吗?
preg_match('~code=(\d+),$content,$match)$代码=$match[1]基本上
$rand=mt_rand(10009999);echo“code=”.$rand将生成一个4位随机数。(快速和肮脏)