PHP Code


PHP Code& Webmaster / SEO22 Jun 2006 02:45 pm

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:
  1. <?php
  2. $string = "This is a test of the Emergency Broadcasting system...";
  3. $string = strtoupper($string);
  4. echo $string;  // echos - THIS IS A TEST OF THE EMERGENCY BROADCASTING SYSTEM...

Note: This function is binary-safe.

PHP Code01 May 2006 10:46 am

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:
  1. <? include("header.php") ?>

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

PHP Code25 Apr 2006 10:09 am

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

CODE:
  1. <?php
  2.  
  3. // set your infomation.
  4. $dbhost='localhost';
  5. $dbusername='username';
  6. $dbuserpass='mypassword';
  7. $dbname='test';
  8.  
  9. // connect to the mysql database server.
  10. $link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);
  11. echo "success in database connection.";
  12.  
  13. // create the database.
  14. $dbname=$dbusername."_".$dbname;
  15. if (!mysql_query("CREATE DATABASE $dbname")) die(mysql_error());
  16. echo "success in database creation.";
  17.  
  18. ?>

PHP Code21 Apr 2006 07:04 pm

Retrieving last modified timestamp for a file

CODE:
  1. <?php
  2. //set path/filename or passed from form argument
  3. $filename = '/path/filename.dat';
  4. // checks that the file actually exists and queries the last modified timestamp
  5. if (file_exists($filename)) {
  6.         echo "$filename exists";
  7.         echo " last timestamp: " . date("d-m-y", filemtime($filename));
  8. } else {
  9.         echo "$filename does not exist";
  10. }
  11. ?>

PHP Code21 Apr 2006 07:00 pm

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

CODE:
  1. <?php
  2. //set the filename or passed from form argument
  3. $filename = "/path/filenane.ext";
  4. //does the file exist?
  5. if (!file_exists($filename)) {
  6. //create the filename
  7.         touch($filename);
  8. //set permissions
  9.         chmod($filename,666);
  10. }
  11. ?>


Payday Advance - MPAA - Credit Counseling - Project Management Software - Consolidation Loans
X10 Home Security|Dakar's Photos
Listed on BlogShares