gpt4 book ai didi

php - 查找特定文本,直到发现它停止

转载 作者:可可西里 更新时间:2023-10-31 23:21:33 25 4
gpt4 key购买 nike

我想知道该怎么做,如您所知,这段代码将获取特定的行,现在我需要它读取直到特定文本(如 55)并从那里停止读取。如您所见,日志中包含一些空格,那么我可以使用什么函数来读取代码 55?

$row['MtID'] = 用于指定结果所在行的唯一 ID。

例如,结果的日志将是

MM3,67624563 (唯一ID (MtID),233262345599, http://mywebsite.com:8080/web/mm3_pixel.php?sspdata=ams1CIv44qa26LGkchACGKqShLrCtZieSyINNDEuMTkwLjg4LjIwOCgB&vurlid=993211,http://mywebsite.net/sspx?id=69171&sspdata=ams1CIv44qa26LGkchACGKqShLrCtZieSyINNDEuMTkwLjg4LjIwOCgB >> OK,55

$logfile = file("https://myweb.com/Pixel-Full.php?file=".$country."/".$today."-pixel-response.log");

foreach($logfile as $line_num = > $line) {
if (strpos($line, $row['MtID']) !== false) {
$getresult = strstr(htmlspecialchars($line), 'http://');
echo "<td>".$getresult."</td>";
}
}

这个系统是这样的,一个用户请求了一些东西,但是没有找到,所以在我们的日志中,它会发布用户请求的错误链接和错误代码,让我们知道它是什么问题。因此,一旦系统读取该行并继续读取其他行,直到找到代码,它就会停止

最佳答案

 $startline = count($logfile)+1;
foreach($logfile as $line_num => $line) {
if (strpos($line, $row['MtID']) !== false) {
$startline = $line_num;
$getresult = trim(strstr(htmlspecialchars($line), 'http://'));
if (strpos($getresult, ",55") !== false) {
$getresult = substr($getresult,0,strpos($getresult, ",55")+3);
break;
}
}
if ($line_num > $startline) {
$getresult .= trim(htmlspecialchars($line));
if (strpos($getresult, ",55") !== false) {
$getresult = substr($getresult,0,strpos($getresult, ",55")+3);
break;
}
}
}
echo "<td>".$getresult."</td>";

关于php - 查找特定文本,直到发现它停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18529461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com