开发者

Is there a function that can read a php function post-parsing?

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 hashe开发者_开发知识库s 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);


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜