Archive for the Category ◊ PHP Code ◊

22 Jun 2006 php case change
 |  Category: PHP Code, Webmaster / SEO  | Leave a Comment

This is available for PHP 3, PHP 4, & PHP 5.

strtoupper — Make a string uppercase

Description
string strtoupper ( string )

Returns string with all alphabetic characters converted to uppercase.

Note that ‘alphabetic’ is determined by the current locale. For instance, in the default “C” locale characters such as umlaut-a (รค) will not be converted.

Example 1. strtoupper() example
[code]
$string = "This is a test of the Emergency Broadcasting system...";
$string = strtoupper($string);
echo $string; // echos - THIS IS A TEST OF THE EMERGENCY BROADCASTING SYSTEM...
[/code]

Note: This function is binary-safe.

01 May 2006 php includes
 |  Category: PHP Code  | Leave a Comment

php includes – rather than rewrite several lines of code for each page, for example adding a standardized header (or footer) to hundreds of pages, using a php include can save a lot of effort, especially when it comes time that you want to make universal changes across your site….. edit one file ie… header.php and every page calling for it’s header from this file is changed in single shot.

[code]
< ? include("header.php") ?>
[/code]

There are as many uses for using includes as you can imagine, populating a set list of variables, database connection strings…

25 Apr 2006 Create mysql database using PHP
 |  Category: PHP Code  | Leave a Comment

Simple code to use php to create a database for you.

[code]
< ?php

// set your infomation.
$dbhost='localhost';
$dbusername='username';
$dbuserpass='mypassword';
$dbname='test';

// connect to the mysql database server.
$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);
echo "success in database connection.";

// create the database.
$dbname=$dbusername."_".$dbname;
if (!mysql_query("CREATE DATABASE $dbname")) die(mysql_error());
echo "success in database creation.";

?>
[/code]

21 Apr 2006 Get file last modified timestamp
 |  Category: PHP Code  | One Comment

Retrieving last modified timestamp for a file

[code]
< ?php
//set path/filename or passed from form argument
$filename = '/path/filename.dat';
// checks that the file actually exists and queries the last modified timestamp
if (file_exists($filename)) {
echo "$filename exists";
echo " last timestamp: " . date("d-m-y", filemtime($filename));
} else {
echo "$filename does not exist";
}
?>
[/code]

21 Apr 2006 Touching a file using PHP
 |  Category: PHP Code  | One Comment

Using php to create or touch a file, first checks to see if it already exists.

[code]
< ?php
//set the filename or passed from form argument
$filename = "/path/filenane.ext";
//does the file exist?
if (!file_exists($filename)) {
//create the filename
touch($filename);
//set permissions
chmod($filename,666);
}
?>
[/code]