Search
Syndication
Sponsors

Archive for the ‘Beginner’ Category

What version of PHP

Thursday, September 10th, 2009

I was asked how to get the version of PHP , this was due to the minimum requirements of a script stating PHP 5 and  a user wanted to know how he could check what his host supplied.

This is the simplest version, save as version.php, upload and  then open it in your web browser.

<?php
echo phpversion();
?>

On my XAMPP installation it displayed 5.2.6

PHP version

Friday, March 6th, 2009

This will display the version of PHP you are using

<?php
echo “<br>I am using “.PHP_VERSION;
?>

Explode A File Example

Wednesday, March 4th, 2009

The test text file was actually an article, this example will look for full stops in the text and output each line as a new line.

<?php
   $file = file_get_contents(”test.txt”);

   $contents = explode(”.”,$file);
   foreach ($contents as $content)
   {
   echo “$content<br/>”;
   }
?>

Read a text file into an array

Wednesday, March 4th, 2009

Read a text file into an array

<?php
   $file = file_get_contents(”test.txt”);

   // Place the contents of test.txt in an array
   $contents = explode(”\n”,$file);

   foreach ($contents as $content)
   {
      echo “$content”;
   }
?>

Add to an array

Wednesday, February 25th, 2009

Add to an array using array_push

<?php
   $search = array(”google”,”yahoo”,”live”,”google”,”yahoo”,”google”);
   print_r($search);
   print “<br>”;
   //lets add a couple of values and print them out again
   array_push($search,”google”,”live”);
   print_r($search);
?>

The result will be

Array ( [0] => google [1] => yahoo [2] => live [3] => google [4] => yahoo [5] => google )
Array ( [0] => google [1] => yahoo [2] => live [3] => google [4] => yahoo [5] => google [6] => google [7] => live )