30

This function will open CSS file read it’s styles and separate selectors from property value pairs. The function stores the values in two array sessions (names and styles). The values can be then easily retrieved using loops or if/else statements.

PHP functions used

trim – Strip whitespace (or other characters) from the beginning and end of a string
This function returns a string with whitespace stripped from the beginning and end of str.

strtok – Tokenize string
strtok() splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token. That is, if you have a string like “This is an example string” you could tokenize this string into its individual words by using the space character as the token.

strstr – Find first occurrence of a stringReturns part of haystack string from the first occurrence of needle to the end of haystack.

count – Count elements in an array, or properties in an objectReturns the number of elements in var, which is typically an array, since anything else will have one element.

Related Posts:

28

MySQL left or right JOIN can be very helpful and it refers to the order in which the tables are put together and the results are displayed.

Left Join

When using LEFT JOIN all rows from the first table will be returned whether there are matches in the second table or not. For example, if table users contains users main information and table options contains users optional information, any records in options table would be tied to a particular id in the users table.read more

Related Posts:

23

Drawing shapes and lines with PHP is nothing like drawing with image editing program. Actually, when drawing with PHP you become the editing program. You use individual PHP functions to define colors, draw and fill shapes, re-size and save the image. These functions are part of the Thomas Boutell’s GD graphics library that was bundled beginning with PHP version 4.3.0.read more

08

I worked on a PHP project where I needed to add and delete rows from an HTML table located in a simple .html file without any database support. The data for the table was provided by a web service. My HTML table looked something like this:

Write HTML table to a file and surround each row with HTML comments containing unique id.

Use preg_replace function to find the row surrounded with unique comment and modify it.

How to…
First I had to figure out the file structure. In my case I needed three files:

file that contains the table

file to display table

file that executs requests.

1. File that contains the table

Knowing that with PHP I can append text at the end of file, I needed to create an HTML table that would allow me to add rows to it. Here is what I came up with:

Filename: table_include.html

Column one

Column two

Notice the comment about not including closing “TBODY” and “TABLE” tags.

2. File that displays table.

The table needed to be displayed in a “DIV” element.

File name: my_table.php

echo '

'; include("table_include.html"); echo'

';

Using PHP include function, I am including table_include.html file and completing table code by adding and below the include. In my case the table rows were generated dynemically as part of a different process. But one important part of the table row generating script was to surround each row with an HTML comment containing a uniqe string. I chose to use PHP’s time() function for unique code. The table code looked something like this: