$username = 'yes';
$password = 'of_course';
$messages = array(
array('to'=>'+001822901920', 'body'=>'Hello World!'),
array('to'=>'+001822901922', 'body'=>'Hello World!')
);
Loading
$username = 'yes';
$password = 'of_course';
$messages = array(
array('to'=>'+001822901920', 'body'=>'Hello World!'),
array('to'=>'+001822901922', 'body'=>'Hello World!')
);
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mrunali SawantPosted Jun 6, 2024, 5:19 AM
To convert the
arrayto a string using theinputvalue in PHP, you can use thejson_encodefunction to convert the array into a JSON string, which is a common and easy-to-read format. Here's how you can modify your PHP code to achieve this:IsraelPosted May 13, 2024, 8:44 AM
The fully code is here, I would like to insert value into two input (one for number and another one for message). Than using "array".
$username = 'yes';
$password = 'of_course';
$messages = array(
array('to'=>'+243822901920', 'body'=>'Hello World!'),
array('to'=>'+243822901922', 'body'=>'Hello World!')
);
$result = send_message( json_encode($messages), 'https://api.x.com/v1/messages?auto-unicode=true&longMessageMaxParts=30', $username, $password );
if ($result['http_status'] != 201) {
print "Error sending: " . ($result['error'] ? $result['error'] : "HTTP status ".$result['http_status']."; Response was " .$result['server_response']);
} else {
print "Response " . $result['server_response'];
// Use json_decode($result['server_response']) to work with the response further
}
function send_message ( $post_body, $url, $username, $password) {
$ch = curl_init( );
$headers = array(
'Content-Type:application/json',
'Authorization:Basic '. base64_encode("$username:$password")
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_body );
// Allow cUrl functions 20 seconds to execute
curl_setopt ( $ch, CURLOPT_TIMEOUT, 20 );
// Wait 10 seconds while trying to connect
curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 10 );
$output = array();
$output['server_response'] = curl_exec( $ch );
$curl_info = curl_getinfo( $ch );
$output['http_status'] = $curl_info[ 'http_code' ];
$output['error'] = curl_error($ch);
curl_close( $ch );
return $output;
}
?>
Mayooran NavamanyPosted May 10, 2024, 4:43 AM
An input value from the user (assuming it's passed via GET method), then retrieves the corresponding message from the
$messagesarray and converts it to a string format.