...

View Full Version : need help with this script



jerry4all
08-22-2011, 06:33 PM
Hi,
this is a part of a script I'm using to send url to an sms gateway.


$param["username"] = "test@yahoo.com";
$param["password"] = "12345";
$param["msg"] = "This is sample message.";
$param["to"] = "2348023555555";
$param["from"] = "MyCompany";

foreach($param as $key=>$val){
//this is to urlencode the values
$request.= $key."=".urlencode($val);
//append the ampersand (&) sign after each paramter/value pair
$request.= "&";
}
//remove the final ampersand sign from the request
$request = substr($request, 0, strlen($request)-1);


my problem is with the username which is an email address, after the encoding the username appears as "%40" in the url that is sent. Is there a way I can prevent this so that it retains the "@" symbol in the resulting $request

Nightfire
08-22-2011, 06:41 PM
Replace


$request.= $key."=".urlencode($val);


With


if($key != 'username'){
$request.= $key."=".urlencode($val);
}

jerry4all
08-22-2011, 07:52 PM
Thanks for the reply, but that will take out the username from the result... I'm not trying to take out the username but rather make it display the "@" symbol and not the encoded "%40"
the result should be this:
username=test@yahoo.com&password=12345&msg=This+is+sample+message.&to=234802888888&from=MyCompany

and not this:
username=test%40yahoo.com&password=12345&msg=This+is+sample+message.&to=2348028888&from=MyCompany

hope it's clearer

Nightfire
08-22-2011, 08:39 PM
oops, I meant to say replace it with this


if($key == 'username'){
$request.= $key."=".$val;
}
$request.= $key."=".urlencode($val);

jerry4all
08-23-2011, 04:14 PM
oops, I meant to say replace it with this


if($key == 'username'){
$request.= $key."=".$val;
}
$request.= $key."=".urlencode($val);



Thanks a lot...didn't need to be encoded...how come I didn't see that?

jerry4all
08-23-2011, 04:32 PM
but here's another challenge at the end. I av this function at the end of the curl, to output the response from the sms server:

curl_exec($ch)

The sms sever responds with a 4-digit code, depending on the response...but I wish to display something else...eg.

if the response is 1900, I want to display "Message sent successfully".

I've tried if...elseif, doesn't give what I want...another help please



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum