Reputation: 152
first sorry for my english I have array will used by function
Upload text file and every line will be element in array
$fh = fopen("upload/".'1.txt','r');
$conn = array();
while ($line = fgets($fh)) {
$conn[] = $line;
}
fclose($fh);
$wbs->SendBulk($conn, "hello world");
Go To Function
public function SendBulk($targets, $message)
{
echo "Sending " . count($targets) . " bulk messages...<br />";
foreach($targets as $target)
{
$this->wa->sendPresenceSubscription($target);
$this->wa->pollMessages();
$this->wa->sendMessageComposing($target);
sleep(55);
$this->wa->pollMessages();
$this->wa->sendMessagePaused($target);
static::$sendLock = true;
echo "Sending message from " . $this->username . " to $target... ";
$this->wa->sendMessage($target, $message); // Orginal
while(static::$sendLock)
{
//wait for server receipt
sleep(55);
}
}
My Problem If I have in text file 2 or more element in array will send for the last element a message but If i make array like this
$conn= array("565684898", "484849815", "484897987", "515498798");
It work for all elements Please Help
Upvotes: 0
Views: 125
Reputation: 782105
The string returned by fgets()
includes the newline that ends each line. Use rtrim()
to remove it:
$conn[] = rtrim($line);
You can also replace your entire code that reads the file with:
$conn = file('upload/1.txt', FILE_IGNORE_NEW_LINES)
Upvotes: 1