Thursday, 13 October 2016

Cookies in PHP

Introduction to Cookies Cookies are one of the most widely misunderstood concepts of Internet surfing to both users and developers. Many people think that cookies are dangerous, insecure 'things' that let people get your credit card details and what not. This is, for most cases, completely untrue. To the experienced web developer, cookies present a medium for allowing quicker and more user friendly access to your website. Cookies are simply...

PHP in_array function use and examples

PHP in_array function use and examples This short article how to use PHP in_array function with arrays. See the description with usage details and reusable code examples below. The details of how to use in_array with normal or multidimensional arrays is also included. Step 1 - PHP in_array function usage examples PHP in_array function use and examples In cases when you want to check whether a value exists in an array you can use the in_array function. This function checks if a value exists in an array. You can use it...

PHP - Alternating row background colors

<?php/*Description:| This will output a table with alternating row background colors. with this the| user can read the entries much easier|------------------------------------------------------------------------------*/      // just some random data in an array$data = array('this','is','just','an','example','to','show','the','alternating','row','colors');$rows = count($data);// the two colors to switch between$rowcolor1 = '#F0F0F2';$rowcolor2 = '#FFFFFF';// the background colors on mouseover$hovercolor1 = '#BAD4EB';$hovercolor2...

PHP - Functions to find strings inside other strings.

<?php/*------------------------------------------------------------------------------|| |Description:| Functions to find strings inside other strings.|------------------------------------------------------------------------------*/// InStr function// checks for an occurance of a string// within another stringfunction InStr($String,$Find,$CaseSensitive = false){    $i=0;    while(strlen($String) >= $i)    {        unset($substring);       ...

string compare

snippet to check username / password against a text file compares fields seperated by a pipe "|" to strings sent via POST variables  <?php // lets say you have a file where there's on each line something like // username|password $data = file('path/to/file.txt'); // read the file for($x = 0; $x < count($data); $x++) {     $parts = explode('|',$data[$x]);     $name_check = strpos($parts[0],$_POST['name']);     if($name_check === true) // important are the ===     {    ...

PHP - insert at specific location

lets say you have a file where you want to insert a string into an existing file at a specific location. put a key into the file where you want the new text appear, i.e.: ###INSERTHERE### then use this function to insert the new data at this keypoint insert at specific location” makes use of the built-in PHP functions file_exists( ), is_writeable( ), filesize( ), clearstatcache( ), fopen( ), fread( ), strpos( ), fclose( ), ftruncate( ), strtr( ) and fwrite( ). <?php /* Description: | lets say you have a file where you want to insert a...

Automatically create a link to this URL

This script will detect URLs in a string and automatically create a link to this URL. it removes the query-string and shows only the top-level of the site linked to as text. “autolink” makes use of the built-in PHP functions preg_replace( ).  <?php $txt = '  <p>      this is a string with      an url in it http://fundisom.com/g5/ and      its enough to be like that  </p>';    $txt = preg_replace('/(http|ftp)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/i',...

Wednesday, 12 October 2016

Creating and Editing Excel Spreadsheets in PHP

To create or edit Excel spreadsheets using pure PHP, we will use the PHPExcel library, which can read and write many spreadsheet formats, including xls, xlsx, ods and csv. Before we continue, double-check that you have PHP 5.2 or higher on your server and that the following PHP extensions are installed: php_zip, php_xml and php_gd2. Creating a Spreadsheet Creating a spreadsheet is one of the most common use cases in PHP applications and is used for exporting data to Excel spreadsheet. Look at the following code to see how to create a...

Creating an RSS Aggregator with the PHP SimplePie Library

RSS aggregators such as Google Reader provide a great way to quickly peruse the latest updates and other news from websites that you follow regularly. All you need to do is provide the aggregator with each site's RSS feed location, and the aggregator will retrieve and parse the feed, converting it into a format (HTML in the case of Google Reader) that you can easily peruse. But what if you want to integrate feeds into your website, or create...

Creating MS Word documents on the fly

Introduction Printing HTML pages directly from browsers usually does not give the best printing output, compared to output from word processors such as Microsoft Word. For web-based systems that generate letters, reports and documents, an output that looks authentic and original is very important. Furthermore, printing output directly from browsers is usually dependant on the browser's configuration. Therefore web-based applications may face difficulties in giving the best printing output especially when dealing with large...

Read CSV Data into a PHP Array

The CSV ("Comma Separated Values") file format is one of the oldest in existence that is still used today to exchange data between dissimilar applications. In fact, it's been around for far longer personal computers have! CSV files are often employed to import data from an application such as MS Excel into a database. The glue that holds the import process together can be any programming language, but, as we'll see here today, there are some very good reasons why PHP is one of the best for this purpose. In today's tutorial, we'll write...