diff --git a/README.md b/README.md index 26fcde2..48989a7 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,10 @@ Parameters for the sendSMS function in order: ## Requirements ## The class requires PHP5 and the PHP5 cURL module (php5-curl on Debian systems). +## Examples ## +In the examples directory are two easy to follow example on how this class can +be used. Both examples should work out of the box as is. + ## Copyright ## This class is written by Jack-Benny Persson and released under GNU GPL version 2. diff --git a/examples/sms_as_args.php b/examples/sms_as_args.php new file mode 100644 index 0000000..e27bbc8 --- /dev/null +++ b/examples/sms_as_args.php @@ -0,0 +1,55 @@ + <'quoted text message'>\n"; + exit(1); +} + +// put arguments into "real" variables for readability +$phone = $argv[1]; +$message = $argv[2]; + +// check if the phone number looks valid +if (!preg_match("/\d{7,16}/", $phone)) +{ + print "That dosen't look like a valid phone number\n"; + exit(1); +} + +// instatiate the class +$cliSMS = new Cellsynt("myuser", "sEcReT", "alpha", "From CLI"); +// call the sendSMS function with the phone number and message +$status = $cliSMS->sendSMS($phone, $message); + +// check for an OK message at the start of the line, in that case everything +// was fine +if (preg_match("/^OK/", $status)) +{ + print "Message was sent successfully. Status message reads:\n"; + print $status . "\n"; + exit(0); +} +// if there were no OK message, something didn't work +else +{ + print "Something didn't work out as expected. Status message reads:\n"; + print $status . "\n"; + exit(1); +} + +// if we got to down here, something was wrong, exit with status code 1 +exit(1); + +?> diff --git a/examples/webpage.php b/examples/webpage.php new file mode 100644 index 0000000..5ba1885 --- /dev/null +++ b/examples/webpage.php @@ -0,0 +1,49 @@ + +
+" . $MySMS->sendSMS($phone, $message) . "
\n"; +} + +?> + + +