# April 2009

## Katrina Costedio Steals (KatrinaCostedio.com)

Katrina Costedio currently lives in Sarasota, Florida and has a small design firm (katrinacostedio.com) that attends to small business needs doing all kinds of design work: print design, card design, logo design and web design. She’s planning to go to San Francisco, California, though. I worked for her on 2 projects, namely maahs acupuncture clinic …

## I dismiss SEO

Other than a descriptive title and a few describing words about what the current page is about, there’s no more needed to be done SEO-wise. No more. Period. Why, when I can create art, fulfill dreams, amuse and please my users and make them feel they have never been treated so well on other sites, …

## MySQL: Add Statistics Column for the Number Count of Records from Another Table

It’s hard to describe this scenario precisely with limited title length. Basically, this is when you want to dedicate a field in ‘category‘ table to store the number of articles or posts in ‘post‘ table that fall into this category. Previously, you had both ‘category’ table to store post categories and ‘post’ table to store …

## PHP: Convert between Numerical Bases | Binary Number, Decimal Number, Octal Number and Hexadecimal Number Conversions

Different number notations for different numerical bases: 0144 // base 8 100 // base 10 0x64 // base 16 To convert between number bases, use PHP base_convert() function: \$hex = ‘a1’; // hexadecimal number (base 16) \$decimal = base_convert(\$hex, 16, 10); // \$hex converted from base 16 to base 10 and \$decimal is now 161 …

## PHP: Convert Degrees to Radians and Convert Radians to Degrees

Degrees and radians are different metric means to gauge an angle. They are mutually convertible in PHP. Simply use the PHP degrees to radians function deg2rad() and PHP radians to degrees function rad2deg(). \$degrees = 180; \$radians = deg2rad(\$degrees); // 3.1416 \$degrees = rad2deg(\$radians); // 180 Because trigonometric calculations are usually done in radians, you …

## PHP: Number Format Function to Format Numbers in PHP (Integer or Float)

To display numbers to end users, especially large numbers, you may need to format them to be more user friendly. For example, with a large integer 43386000.75, it is usually preferred to comma-separate every 3 digits to this: 43,386,000.75 To format numbers this way in PHP, you need number_format() function: print number_format(43386000.75); // prints ‘43,386,000.75’ …

## PHP: Send HTML Email (mail)

As we all know the simplest approach to create an email message and send it out is to use the php mail() function. A typical usage example would be: mail(‘[email protected]’, ‘Subject Title’, ‘Message body goes here.’); However, as the mail() function sends emails in text/plain mime type by default, if you include HTML code in …

## PHP: Wrap Long Lines | Insert Line Breaks into a Long String

Some strings of texts may lack necessary wraps and don’t have natural line breaks in them so that the lines are too long to read comfortably. Therefore, you want a way to insert line breaks in to the string every dozens of characters. The php function you need is wordwrap(): \$s = ‘ … ‘; …

## PHP String Case: Uppercase all Letters or Lowercase all Letters in a String | Uppercase First Letter of a String | Uppercase First Letter of all Words in a String

It’s common that you need to reformat the texts in PHP and make them look a little more formal. For example, the first letter of all sentences should be uppercased, or with a title, the first letter of all words should also be made uppercase; in other situations, you may want all letters to be …

## PHP: Change Tabs to Spaces and Vice Versa in String | Change Tab Sizes / Lengths in Strings

Everyone who ever dealt with formatting code in PHP string manipulations may want to switch between different tab sizes or simply change spaces to tabs or tabs to spaces in the formatted code string. The function we’ll need for these is str_replace(), the string search and replace php function. For example: Switch between tabs and …

## PHP: How to process a string one byte (character) at a time

If you want to loop through a literal string in PHP and have the opportunity to look and process each of the characters one character at a time, use the following snippet: \$string = "Hooray"; for (\$i = 0, \$j = strlen(\$string); \$i < \$j; \$i++) { echo \$string[\$i].’, ‘; } There you go, just …

## PHP: Check if a string contains another string or substring

As a web site templating language, string processing is what PHP is good at. There’s always a chance that you need to verify and make sure if a string contains another string. For example, to check if an at sign is included in the entered email address by a visitor: if (strpos(\$_POST[’email’], ‘@’) !== false) …

## PHP: Getting the Current Date and Time

Programmably, there are several different types of date and time in PHP you can create and process. Consequently, you have several types of current date and time in PHP that can be generated and used. Below is a list of functions that returns the current date and time: The current Unix timestamp: time() The current …

## PHP: How to access a global variable inside a function without passing it?

Ideally, global variables outside a function can not and should not be accessed from within the function to hold up the programming modularization paradigm. However, if you really need to do this, especially in small programs, you can declare the variable again inside the function by the keyword ‘global‘ so as to use inside the …

## PHP: Detecting Different Browsers

As we all know that JavaScript is usually what involves in detecting different browsers and their varying capabilities. PHP has the very function that parses the HTTP request headers sent by client web browsers so as to determine the identify of the requesting browser as well as its capabilities. To get client browser information and …

## PHP cURL: Fetching URL and Sending Request with Cookies

One of the things the remote web server inspects is the client cookie to know about the requester. If you need cURL to simulate a user browser that sends cookie information to the web server, you need the following options: \$c = curl_init(‘http://www.example.com/needs-cookies.php’); curl_setopt (\$c, CURLOPT_COOKIE, ‘user=ellen; activity=swimming’); curl_setopt (\$c, CURLOPT_RETURNTRANSFER, true); \$page = curl_exec …

## PHP cURL: Making POST Request to URL

By default, all HTTP requests made out by cURL is GET requests that simply fetches the URL and don’t submit any more POST variables. However, if you need to fetch and retrieve URL by the POST method with cURL, you need the snippet below: \$url = ‘http://www.example.com/submit.php’; // The submitted form data, encoded as query-string-style …

## PHP: GD Library Drawing Functions Reference

To draw a line, use ImageLine( ): ImageLine(\$image, \$x1, \$y1, \$x2, \$y2, \$color); To draw an open rectangle, use ImageRectangle( ): ImageRectangle(\$image, \$x1, \$y1, \$x2, \$y2, \$color); To draw a solid rectangle, use ImageFilledRectangle( ): ImageFilledRectangle(\$image, \$x1, \$y1, \$x2, \$y2, \$color); To draw an open polygon, use ImagePolygon( ): \$points = array(\$x1, \$y1, \$x2, \$y2, …

## PHP: Change Error Reporting Level | Different PHP Error Types

Debugging a PHP script, you may want to alter the error-displaying sensitivity on a particular page and control what types of errors should be reported. The solution is the PHP error reporting function error_reporting(): error_reporting(E_ALL); // everything error_reporting(E_ERROR | E_PARSE); // only major problems error_reporting(E_ALL & ~E_NOTICE); // everything but notices As the parameters of …

## PHP: What is Hash? | Hashing a String | Generate Hash of Strings

A hash or digest can be thought of as the digital fingerprint of a piece of data. Hash is usually generated from any string of text in a fixed length by a one-way mathematical process. It is next to impossible to re-engineer the original text or data from the hash alone. Also, it is vast …

Scroll to Top