有没有一个函数可以在解析后读取php函数?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是修改第一个 php 文件,它会回显所有内容,如下所示:
echo
的每个实例更改为例如$data[] =
,执行foreach($data as $d) echo $d
(这将产生与您现在相同的结果),$data
数组可以循环并用它做任何你喜欢的事情。为了提供工作代码示例,如果您可以发布文件的当前代码,那就太好了。
编辑
如果您像这样更改脚本:
...您将拥有包含键中每个散列的数组 $data 。然后你可以像这样循环遍历这个数组:
The easiest thing to do would be to modify your first php file which echoes everything, along these lines:
echo
to e.g.$data[] =
foreach($data as $d) echo $d
(this will produce the same result as you have right now)$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:
...you'll have the array $data that contains each hash in a key. You can then loop through this array like so: