Location: PHPKode > scripts > mobilyws SMS > mobilyws-sms/mobilyws.class.php
<?php
/**
 * Mobily.ws (SMS Gateway) Class 
 * Done by Mohammed Shannaq
 * www.phpspiders.com 
 * hide@address.com 
 * Class version: 1.0
 * Created Date: 1-may-2007
 * Last Modify: 02-may-2007 (By Me)
 *  
 * ***** submitted text tested using windows-1256  *****
 * ***** if you want to use utf-8 text convert the *****
 * ***** file encoding to utf-8                    *****
 * 
 * This class comes with the BSD license,
 * http://www.opensource.org/licenses/bsd-license.html
 * 
 * Also you need a vaild account on mobily.ws to send SMS's
 */
class mobilyws
{
	/**
	 * mobilyws main class function
	 *
	 * @param string $account_username
	 * @param stringe $account_password
	 * @return mobilyws
	 */
	function mobilyws($account_username,$account_password)
	{
		$this->username = $account_username;
		$this->password = $account_password;
	}
	/**
	 * This function used to get account balance
	 *
	 * @return Array [connected]: (true,false) [result]: the result
	 */
	function get_balance(){
		$url = "http://www.mobily.ws/smsCenter/balance.php?userName=".$this->username."&userPassword=".$this->password."";
		if (!($fp =@fopen($url,"r"))){
			$rarray['conncted'] = false;
		} else {
			$rarray['conncted'] = true;
		}
		$rarray['result'] = @fread($fp,100);
		//balance will come as 10:7 {account_total:account_current_credit}
		@fclose($fp);
		return $rarray;
	}
	/**
	 * This function to send SMS
	 *
	 * @param string $from (name or number not more that 14 chars)
	 * @param string $to (you can use multi numbers as no,otherno,anotherno) and upto 120 mobile number as mobily.ws said, but I advise to use on number every call.
	 * @param string $sms_msg
	 * @return integer
	 * (result code => 0: cannot connect to mobily.ws gateway
	 *                 1: send ok
	 *                 2: cannot sned, the account balance is empty
	 *                 3: cannot send, no enough credit
	 *                 4: cannot send, incorrect username
	 * 				   5: cannot send, incorrect password
	 */
	function send_sms($from,$to,$sms_msg){
		$utf16msg = $this->Convert2UTF16($sms_msg);
		//echo $sms_msg;
		$url = "http://www.mobily.ws/smsCenter/sendSms.php?userName=".$this->username."&userPassword=".$this->password."&numbers=".$to."&userSender=".$from."&msg=".$utf16msg."";

		
		if (!($fp = @fopen($url,"r"))){
			$result = "0"; //unable to connect to the url
		}
		$result = @fread($fp,10);
		@fclose($fp);
		return $result;
		
		//echo $utf16msg;
	}
	/**
	 * This Function Converting the given text to UTF-16
	 * UTF-16 required when sending SMS
	 * 
	 * This function support Arabic,English and the special chars only
	 * For other language try to move your hands
	 * 
	 * This is internal function
	 * 
	 * @param string $text2convert
	 * @return utf-16_string
	 */
	function Convert2UTF16($text2convert){
		$utf16 = array(
		"060D" => "¡" ,
		"060D" => "¡",
		'061B' => "º",
		'061F' => "¿",
		'0621' => "Á",
		'0622' => "Â",
		'0623' => "Ã",
		'0624' => "Ä",
		'0625' => "Å",
		'0626' => "Æ",
		'0627' => "Ç",
		'0628' => "È",
		'0629' => "É",
		'062A' => "Ê",
		'062B' => "Ë",
		'062C' => "Ì",
		'062D' => "Í",
		'062E' => "Î",
		'062F' => "Ï",
		'0630' => "Ð",
		'0631' => "Ñ",
		'0632' => "Ò",
		'0633' => "Ó",
		'0634' => "Ô",
		'0635' => "Õ",
		'0636' => "Ö",
		'0637' => "Ø",
		'0638' => "Ù",
		'0639' => "Ú",
		'063A' => "Û",
		'0641' => "Ý",
		'0642' => "Þ",
		'0643' => "ß",
		'0644' => "á",
		'0645' => "ã",
		'0646' => "ä",
		'0647' => "å",
		'0648' => "æ",
		'0649' => "ì",
		'064A' => "í",
		'0640' => "Ü",
		'064B' => "ð",
		'064C' => "ñ",
		'064D' => "ò",
		'064E' => "ó",
		'064F' => "õ",
		'0650' => "ö",
		'0651' => "ø",
		'0652' => "ú",
		'0021' => "!",
		'0022' => "\"",
		'0023' => "#",
		'0024' => "$",
		'0025' => "%",
		'0026' => "&",
		'0027' => "\'",
		'0028' => "(",
		'0029' => ")",
		'002A' => "*",
		'002B' => "+",
		'002C' => ",",
		'002D' => "-",
		'002E' => ".",
		'002F' => "/",
		'0030' => "0",
		'0031' => "1",
		'0032' => "2",
		'0033' => "3",
		'0034' => "4",
		'0035' => "5",
		'0036' => "6",
		'0037' => "7",
		'0038' => "8",
		'0039' => "9",
		'003A' => ":",
		'003B' => ";",
		'003C' => "<",
		'003D' => "=",
		'003E' => ">",
		'003F' => "?",
		'0040' => "@",
		'0041' => "A",
		'0042' => "B",
		'0043' => "C",
		'0044' => "D",
		'0045' => "E",
		'0046' => "F",
		'0047' => "G",
		'0048' => "H",
		'0049' => "I",
		'004A' => "J",
		'004B' => "K",
		'004C' => "L",
		'004D' => "M",
		'004E' => "N",
		'004F' => "O",
		'0050' => "P",
		'0051' => "Q",
		'0052' => "R",
		'0053' => "S",
		'0054' => "T",
		'0055' => "U",
		'0056' => "V",
		'0057' => "W",
		'0058' => "X",
		'0059' => "Y",
		'005A' => "Z",
		'005B' => "[",
		'005C' => "\\",
		'005D' => "]",
		'005E' => "^",
		'005F' => "_",
		'0060' => "`",
		'0061' => "a",
		'0062' => "b",
		'0063' => "c",
		'0064' => "d",
		'0065' => "e",
		'0066' => "f",
		'0067' => "g",
		'0068' => "h",
		'0069' => "i",
		'006A' => "j",
		'006B' => "k",
		'006C' => "l",
		'006D' => "m",
		'006E' => "n",
		'006F' => "o",
		'0070' => "p",
		'0071' => "q",
		'0072' => "r",
		'0073' => "s",
		'0074' => "t",
		'0075' => "u",
		'0076' => "v",
		'0077' => "w",
		'0078' => "x",
		'0079' => "y",
		'007A' => "z",
		'007B' => "{",
		'007C' => "|",
		'007D' => "}",
		'007E' => "~",
		'00A9' => "©",
		'00AE' => "®",
		'00F7' => "÷",
		'00F7' => "×",
		'00A7' => "§",
		'0020' => " ",
		'000D' => "\n");
		for($i=0;$i<strlen($text2convert);$i++)
		{
			foreach ($utf16 as $key => $value) {
				if ($text2convert[$i] == $value)
				$utf16string .= $key;
			}
		}
		return $utf16string;
	}
}
?>
Return current item: mobilyws SMS