Hello :) I apologize in advance if this is really dumb, but I've been trying to figure it out for a week and now I'm about to explode :D
I have a list of 200 ID numbers in a text file, each are separated by a newline. I want to use PHP to use each line, one by one, as a variable in a POST request. I can use this code to send the first line, by specifying the number of characters to include from the file:
$IDfile = "file.txt";
$fh = fopen($IDfile, 'r');
$ID = fread($fh, 18);
fclose($fh);
Then I can use the $ID variable in the POST. But this is only good for the first line, since there are 18 characters in the line, but there are 199 more lines.
I can also print all the lines in the file with a foreach, but this won't help with the POST requests:
$IDfile = "file.txt";
$lines = file($IDfile);
foreach($lines as $line_num => $line)
{
echo $line;
echo "<br>";
}
So, here is the full script of my POST request, to send a "destroy tweet" command to the Twitter API 1.1 - The $ID variable is the one I want to replace using every line in the text file sequentially:
require_once('TwitterAPIExchange.php');
include('apikeys.php');
$url = "https://api.twitter.com/1.1/statuses/destroy/" .$ID . ".json";
$requestMethod = 'POST';
$postfields = array(
);
$twitter = new TwitterAPIExchange($settings);
$twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();
So how do I do it? How can I get each line sequentially from the text file, and then use the single line value as a variable in the POST request, until each has been read?
This is probably way out of my league lol, but I am determined to learn this, and any help or direction would be so very gratefully received :)