gpt4 book ai didi

php - 如何使用 PHP Stripos 搜索 txt 中的字符串

转载 作者:行者123 更新时间:2023-12-02 20:36:11 24 4
gpt4 key购买 nike

我有一个包含

的文本文件

数字,零,一

数字,二,三

数字,四,五

在名为 data.txt 的文件中

我想搜索该号码并尝试了此操作,但似乎不起作用

$file = 'domain.com/data.txt'; 
$searchnum = 'zero';

if (stripos($file, $searchnum) == true) { echo 'number found' }

更新1.0我也尝试过这个,但它似乎没有提取txt文件上的数据

$file = "domain.com/data.txt";

$searchnum = "zero";
if(exec('grep '.escapeshellarg($searchnum).' '.$file )) {
echo "record found";
}
else {
echo "record notfound";

}

最佳答案

您做得正确,您只需提取文件内容即可。

$file = file_get_contents('./data.txt'); // you can use a full http address if your server allows it
$searchnum = 'zero';

if (stripos($file, $searchnum) !== false) { echo 'number found'; }

关于php - 如何使用 PHP Stripos 搜索 txt 中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47062237/

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