有没有一个函数可以在解析后读取php函数?

发布于 2024-08-29 19:43:53 字数 918 浏览 7 评论 0原文

我有一个 php 文件,它从 MySQL 数据库中回显哈希值。这对于我正在使用的远程程序是必要的,但同时我需要打开其他 php 脚本并检查它是否有指定的字符串 POST 解析。如果它检查字符串预解析,它只会获取 MySQL 查询而不是要查找的字符串。

我不确定是否有任何函数可以做到这一点。 fopen() 在解析之前是否读取文件?或 file_get_contents()?

如果是这样,是否有一个函数可以在 php 和 mysql 代码运行后读取该文件?

带有哈希查询和 echo 的文件与读取它的 php 文件位于同一目录中(如果有区别的话)。

也许 fopen 会在解析后读取它,而我做错了一些事情,但起初我将哈希值直接存储在文件中,并且工作正常。在我将其更改为回显 MySQL 表的内容后,它出错了。

MySQL 查询脚本:

$query="SELECT * FROM list";
$result=mysql_query($query);
while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
 echo $row['hash']."<br>";
 }

我之前使用此脚本从该脚本获取哈希值,当时它只是哈希值列表:

            $myFile = "hashes.php";
            $fh = fopen($myFile, 'r');
            $theData = fread($fh, filesize($myFile));
            fclose($fh);
            $mystring = $theData;
            $findme   = $hash;
            $pos = strpos($mystring, $findme);

I've got a php file echoing hashes from a MySQL database. This is necessary for a remote program I'm using, but at the same time I need my other php script opening and checking it for specified strings POST parsing. If it checks for the string pre-parsing, it'll just get the MySQL query rather than the strings to look for.

I'm not sure if any functions do this. Does fopen() read the file prior to parsing? or file_get_contents()?

If so, is there a function that'll read the file after the php and mysql code runs?

The file with the hashes query and echo is in the same directory as the php file reading it, if that makes a difference.

Perhaps fopen reads it post-parse, and I've done something wrong, but at first I was storing the hashes directly in the file, and it was working fine. After I changed it to echo the contents of the MySQL table, it bugged out.

The MySQL Query script:

$query="SELECT * FROM list";
$result=mysql_query($query);
while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
 echo $row['hash']."<br>";
 }

What I was using to get the hash from this script before, when it was just a list of hashes:

            $myFile = "hashes.php";
            $fh = fopen($myFile, 'r');
            $theData = fread($fh, filesize($myFile));
            fclose($fh);
            $mystring = $theData;
            $findme   = $hash;
            $pos = strpos($mystring, $findme);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

似最初 2024-09-05 19:43:53

最简单的方法是修改第一个 php 文件,它会回显所有内容,如下所示:

  • echo 的每个实例更改为例如
  • 底部的 $data[] = ,执行 foreach($data as $d) echo $d (这将产生与您现在相同的结果),
  • 您现在仍然拥有您的 $data 数组可以循环并用它做任何你喜欢的事情。

为了提供工作代码示例,如果您可以发布文件的当前代码,那就太好了。

编辑

如果您像这样更改脚本:

$query="SELECT * FROM list";
$result=mysql_query($query);
while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
 $data[] = $row['hash']."<br />";
 }
foreach($data as $d) {
     echo $d;
}

...您将拥有包含键中每个散列的数组 $data 。然后你可以像这样循环遍历这个数组:

foreach($data as $d) {
  //do something
}

The easiest thing to do would be to modify your first php file which echoes everything, along these lines:

  • change every instance of echo to e.g. $data[] =
  • at the bottom, do foreach($data as $d) echo $d (this will produce the same result as you have right now)
  • you now still have your $data array which you can loop through and do whatever you like with it.

To provide working code examples, it would be great if you could post the current code of your file.

EDIT

If you change your script like so:

$query="SELECT * FROM list";
$result=mysql_query($query);
while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
 $data[] = $row['hash']."<br />";
 }
foreach($data as $d) {
     echo $d;
}

...you'll have the array $data that contains each hash in a key. You can then loop through this array like so:

foreach($data as $d) {
  //do something
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文