FacebookTwitter

Export Array to CSV – PHP

By on Aug 29, 2014 in PHP

Export to CSV – PHP CSV (comma-separated values) is the most widely supported format for transferring tabular data. Exporting data in CSV format is very common in web applications. This simple example will help you get started with CSV and PHP. The main goal is to create a simple way to export data from your website or web application into a CSV that can be downloaded by the user. The Code ?View Code PHP1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 <?php function convert_to_csv($input_array, $output_file_name, $delimiter) { /** open raw memory as file, no need for temp files, be careful not to run out of memory thought */ $f = fopen('php://memory', 'w'); /** loop through array */ foreach ($input_array as $line) { /** default php csv handler **/ fputcsv($f, $line, $delimiter); } /** rewrind the "file" with the csv lines **/ fseek($f, 0); /** modify header to be downloadable csv file **/ header('Content-Type: application/csv'); header('Content-Disposition: attachement; filename="' . $output_file_name . '";'); /** Send file to browser for download */ fpassthru($f); } /** Array to convert to csv */ $array_to_csv = Array( Array(12566, 'Enmanuel', 'Corvo' ), Array(56544, 'John', 'Doe' ), Array(78550, 'Mark', 'Smith' ) ); convert_to_csv($array_to_csv, 'report.csv', ','); The Explanation [show_resp_ad] The function convert_to_csv($input_array, $output_file_name, $delimiter) export to csv by taking in a PHP Array ($input_array) as its first parameters and converts it into...

How to Make a Phone Call from your Computer – Getting started with Twilio Voice

By on Aug 14, 2014 in Intermediate, PHP

As you might have noticed from many of my previous posts, I am a big fan of Twilio. The reason is because it is really easy to use, its very reliable, and it is also cheap. There are a ton of cool things you can do with Twilio, from Sending SMS to Receiving and Dialing calls. This simple tutorial will show you how easy it is to use Twilio to place outbound calls. Placing outbound calls using Twilio There are two ways you can dial calls with Twilio. One way is using their Rest API. The other way is using TwiML. With TwiML you don’t have to rely on the Rest API at all. You don’t need to include SDKs, you can do this in a few lines of code in a single file. The only catch to this is that you can only use this method (TwiML) with calls that are already in progress, you cannot initiate a new call leg with TwiML. As opposed to the Rest API, which allow you to initiate call legs. TwiML are meant to control the flow of a call that has already been initiated without having to make requests to the Rest API which could take long sometimes, affecting the overall efficiency of your application. Start dialing out Lets go ahead and create a directory where we will be placing the code to dial outbound calls “/twilio-voice-demo”. The next step is to include the Twilio SDK in this directory so we...

Sending SMS from PC to Mobile

By on Aug 12, 2014 in Intermediate

Sending SMS from PC to Mobile is very easy. This simple tutorial will guide you thought the basic steps to start Sending SMS from your computer to a Mobile device. The first thing you will need to to find an SMS Gateway. For this tutorial I will be using Twilio, a cloud communications company based in San Francisco, California. Start Sending SMS from PC to Mobile Step 1: Sign-up for Twilio. Right of the batch you get a free number and some testing minutes. However, every time you send an SMS or place a call they will play their disclaimer saying that this is a demo account. So if you want to get rid of this message you can go ahead and purchase a number. They are pretty cheap usually 1 dollar a month, and this number you can use for many things not just sending SMS You can use this number for placing and receiving calls. For more information on how to do this check out this tutorial Making phone calls from your computer. I will also advice you to buy some credit, again it is pretty cheap, they only charge $0.01 per minutes for phone calls and $0.0075 per SMS message. Step 2: Now that you have your number and some credit in your account is when all the fun begins. For this tutorial we will be using server-side javascript to send our SMS. We will be doing this by...

Best SMS Gateway

By on Jul 18, 2014 in Interesting

Looking for a reliable (“The Best”) SMS Gateway? Well I got one for you. Actually, I been using this service for quite sometime now, and that is why I feel so comfortable recommending it. It’s name is Twilio. Twilio is very popular for SMS and Voice. It’s very well documented for developers, and even for beginners. In my opinion they have the cleanest API compared to other Gateways. Here are some of the features they offer: Global Text Messaging API Build apps that send and receive SMS using phone numbers and short codes. Let friends say hello, tell customers their packages are delivered or alert employees that a shift is ready. The API enables users to communicate with your app or chat with one another; your code decides. Build Intelligent Communications Twilio lets you use standard web languages to build SMS and voice applications. They’re connected to carrier networks globally and expose them to you via a clean, powerful web API. So bring your favorite programming language, a web server, and build the next generation of communications with them. Cloud Powered They’re built in the cloud. Their API is always available as I already mentioned, continuously upgraded and auto-scales to meet your needs. When you move your communications to the cloud, there are no tricky VPNs to configure or SMPP binds to manage. Just send them your message via HTTP, and they will deliver it anywhere in the world. Why Twilio is The Best SMS Gateway Overall Twilio is...

What is a callback function?

By on Jul 13, 2014 in Definitions

Many people out here are confused by what a callback is. Perhaps the name makes it hard to understand. But in reality callbacks are very simple. A callback function is a function that is passed as an argument of another function and it is invoked after some kind of event. The name “call back” can be attributed to the nature of the function, since once its parent function completes, the function that got passed as an argument gets called. In other words, the parent function “calls-back and executes the function passed as an argument. As you can already imagine, callbacks are extremely useful. They allow for you to call a function within a function. Here you can see some examples: ?View Code JAVASCRIPT1 2 3 4 5 $("button").click(function(){ $("p").hide("slow",function(){ alert("The paragraph is now hidden"); }); }); In this example. Whenever you click a ‘button’ all ‘p’ tags will call the hide() function with parameters “slow” for the speed in which the ‘p’ tag should hide and a second parameter a function, which task is to...