Posts in the "PHP Functions" Category

  • The date() function converts a given timestamp into a readable date format. Here is the syntax for this function: Syntax date(format,timestamp); Parameters: format This parameter determines the format and how the date will read. For example: “Saturday, Nov. 16th 2009” would be the following code: $timestamp = time(); date("l, M. jS Y",$timestamp); timestamp This parameter [...]

    Read More...
  • Here is a very simple function to use to ordinalize numbers in PHP. This adds the place value suffix to numbers. So you can turn numbers like 1, 2, 3 into 1st, 2nd, 3rd. Here is the code: function ordinalize($int){ if(in_array(($int % 100),range(11,13))){ return $int . "th"; } else { switch(($int % 10)){ case 1: [...]

    Read More...
  • Let’s say you want to have a simple HTML <select> form as a drop down for rows in a Mysql table. This could be for things like categories, pages, games, anything you want to have in a drop down to navigate to another page or submit a form. What ever the case is, I’m going [...]

    Read More...
  • Here we’re going to take a look at variables inside and outside of PHP functions. It is very easy to make one error with a function and have it return the wrong value. We’re going to make a simple function named “func1” which we’ll tweak a bit to show how variables are used inside and [...]

    Read More...
  • One of the most common ways to capture the current time in PHP scripting is by using the time() function. This returns the current timestamp which is the number of seconds after a certain date and time in the past. You can use this when entering a mysql query to note the current time of [...]

    Read More...
  • The function switch() in PHP is used to execute different codes based on a variable’s value. This is used in place of the IF/ELSE IF statements. A default value is optional and, if specified, is used when no other option is matched. You must include a break; after each case or the following cases will [...]

    Read More...
  • Previously in a post I made for uploading file with URL we wanted to include a file size check to make sure the file wasn’t too big before we upload it. Here I’ll show you how to get the remote file’s size and other information before doing other functions with it. <form action="get_info.php" method="post"> <input [...]

    Read More...
  • A cookie is a small file that the server embeds on the user’s computer. This data is sent and recieved with each browser that is used to view a page using cookies. To create a cookie in PHP use the setcookie() function. Here is its syntax: setcookie($name, $value, $expire, $path, $domain); So if you want [...]

    Read More...
  • If you have a contact us page or something that sends an email with the use of php, it will use the “mail()” function of PHP. Here is the function: mail(‘Send To’,‘Email Title’,‘Email Message’,‘Headers’,‘Parameters’); Send To = Who the email is being sent to. Email Title = Title of the email, appears in inbox. Email [...]

    Read More...
  • Preg_replace in PHP uses regular expressions to replace matches in the subject with the given replacement. The syntax of preg_replace is as follows: preg_replcae(pattern,replacement,subject [,limit]); A good example of using preg_replace is with simple bbcode and smilies. However with more complex bbcode there are other ways that would proove to be much easier and more [...]

    Read More...

bgallz.org is for training purposes only. Its content is to be used at the risk of the user. We do not guaruntee its accuracy.