Category : "Tutorial"

Php web development tutorials

How to modify a SoapClient request in php

SOAP is a protocol to exchange objects over http. It is used to implement apis and the data being exchanged is in xml format. Sometimes it might be required to modify the soap request to add custom http headers for example. Since SoapClient is a class, it can be extended and the request process can be modified. Here is a quick example The __doRequest method of the SoapClient class is over-ridden and the request is [...]

Socket programming with streams in php

Socket programming involves connecting to remote machines on LAN or over the internet using ip addresses and port number. For example google.com has an ip “173.194.36.3″ and runs http server on port 80. So a socket application can connect to that ip address on that particular port number and start data communication. Socket extension Php comes with a socket extension which provide c-style socket functions and can be used to write socket programs. However the [...]

Parse the user agent with ua-parser in php – detect browser, os and device

In your web application you might need to parse the user’s user-agent string to find out the browser/OS/device being used. This is necessary specially when your webapp tries to adapt to the user’s platform in a better way. For example a different layout for mobile device or restricted features/graceful degradation on a non supporting browser. To do this you can analyse the user agent string in php which is found in the $_SERVER superglobal string. [...]

Convert html to pdf in php using mpdf

Html to pdf If your php application needs to generate some kind of pdf report then the simplest approach would be to generate the report as an html and then convert it to pdf using some library. Plenty of libraries are available that can convert html to pdf in php. To name a few – fpdf, tcpdf, mpdf etc. I found mpdf to be the best library for html to pdf conversion inside php. It [...]

How to use proxy with curl in php

Curl is a very useful library for transferring data over various protocols like http, ftp, https etc. In other words curl can be used to programatically download a web page, or upload file to ftp etc. It also supports using a proxy. This means that curl requests can go through a proxy server just like a web browser does when configured to use a proxy. Using a proxy with curl is very simple and straight [...]

Convert excel to csv in php

When working with data import and export for example, file formats like csv and excel are commonly used. Data can be exported to csv format and imported elsewhere. Also data might be entered manually in an excel file and then imported in the database. So there might be a need to convert excel files to csv format, so that they can be parsed easily and processed. Converting excel files to csv is very easily done [...]

Generate qrcode and pdf417 barcodes in php with tcpdf

Tcpdf is a pdf creation library for php that is written in pure php and works without the need of any external library. It also has the feature to generate 2d barcodes like qrcode and pdf417. The 2d barcodes can store much more information than the 2d ones like code39 and ISBN. It is recommended to generate barcodes inside pdf so that they are printed very accurately on hard media like paper and then read [...]

Php – Output content to browser in realtime without buffering

Consider a long running php script that does many tasks and after each task it outputs the status. echo ‘Task 1 complete’; …. some delay … echo ‘Task 2 complete’; …. more delay and more tasks … Now for such scripts it may be important to load the contents in browser as quickly as they are generated so that the user can understand the progress of the script. If the entire output were to appear [...]

Get the play time and bitrate of an mp3 in php

If your php application is processing media files like mp3, then it might need to find details of the mp3 file like its playtime, bitrate, encoder etc. There is a very useful php library called Getid3 that can extract information from mp3 files. Its written in pure php and does not have any dependencies. Needs php 5.0+. Get it here Here is a quick code example that shows how to find out the playtime of [...]

Php array of iso 3316 country list

Php applications often need to present the user with a list of countries to select his home country from. The iso 3316 country list contains the name of the countries along with the 2 letter codes. Check out the following project on github that contains the uptodate list of the countries in various formats. Here is a sample of the array The country list project contains the country list in various other formats like csv, [...]

Pages:123456»