Installing PEAR in WAMP

So this evening I went about attempting to install PEAR on my WAMP installation, this should be as simple as opening up a command window navigating to C:/wamp/bin/php/*phpversion* and running “go-pear.bat”, however upon doing this I ran into the following errors:

phar “C:\wamp\bin\php\php5.3.0\PEAR\go-pear.phar” does not have a signaturePHP W
arning: require_once(phar://go-pear.phar/index.php): failed to open stream: pha
r error: invalid url or non-existent phar “phar://go-pear.phar/index.php” in C:\
wamp\bin\php\php5.3.0\PEAR\go-pear.phar on line 1236

Warning: require_once(phar://go-pear.phar/index.php): failed to open stream: pha
r error: invalid url or non-existent phar “phar://go-pear.phar/index.php” in C:\
wamp\bin\php\php5.3.0\PEAR\go-pear.phar on line 1236
Press any key to continue . . .

A couple of Google searches later I got the answer needed to fix my problem, simply running this command instead:

php -d phar.require_hash=0 PEAR/go-pear.phar

A couple of questions later PEAR was successfully installed and running, so if your running into the above error you now know what to do! 🙂

Another Re-Design

I_Hate_Eggs_by_Eibo_Jeddah

Image Above ©2010 =Eibo-Jeddah

So here we are, four months into 2010 and I couldn’t stand another minute of looking at the old design! So presto its gone! We are currently using the StudioPress Theme, which has quiet a nice feel to it I think! I have also added a Services page listing Services I can provide and estimate costs..

Other than that we have a contact page up thanks to a handy plug-in Contact Form 7. And we’ve finally gotten around to enabling the “All in One SEO Pack” so hopefully now we’ll get some more “related” traffic!

Currently doing alot of work with Prestashop, but can’t say much on that at the minute, but hopefully by the end of the month I can get a few posts on Prestashop up as well. Other than that just waiting on Microsoft Dreamspark Support to get back to me for a free trial for XNA Game Studio..

Programmer Personality

Just took an interesting test on “What is your programmer personality?” It is based of the Myers-Briggs Personality Test and has been changed to relate to your programming personality type.

Your programmer personality type is:

DLSB

You’re a Doer.
You are very quick at getting tasks done. You believe the outcome is the most important part of a task and the faster you can reach that outcome the better. After all, time is money.

You like coding at a Low level.
You’re from the old school of programming and believe that you should have an intimate relationship with the computer. You don’t mind juggling registers around and spending hours getting a 5% performance increase in an algorithm.

You work best in a Solo situation.
The best way to program is by yourself. There’s no communication problems, you know every part of the code allowing you to write the best programs possible.

You are a liBeral programmer.
Programming is a complex task and you should use white space and comments as freely as possible to help simplify the task. We’re not writing on paper anymore so we can take up as much room as we need.

Find out what kind of programmer you are here!

Snipt.net – Store your Code Snippets Online

Recyclable Code

Often when your programming well you find yourself with a lot of reusable or recyclable code. Everyone has their own little way of keeping all this code and organizing it etc. etc. for their next project. However today I found a great website now that I need my code snippets in more than one place, Snipt.net . Not only can you store all your code privately with the ability to tag it and have it highlighted. But you can browse through the public code also, for when your really stuck with that problem! 😉 This will certainly be a website I’ll be adding to most used for ’09

Learn PHP: Class Three, Includes and Requires

Today we are going to learn all about include and require! Include and require are handy to use not only in your php applications, but in general website design for sidebar’s and what not! So.. yeah.. 😛 Moving on!

Include and Require include a file within another PHP script. There are four ways of doing this:


include();
include_once();
require();
require_once();

Now using them is seriously simple. Lets say you have a file called “sidebar.php” with your links? All you have do do is the following:

include('sidebar.php');

One thing to remember is how to traverse directories in PHP. For instance, if my file “sidebar.php” is in a folder called “includes” you could go:

include('includes/sidebar.php');

Or another approach, if my file “sidebar.php” is in the parent directory, you could go:

include('../sidebar.php');

Now why are there four different ways to include them I hear you ask! Well they are pretty simple.

Include and Require are practically the same, apart from the way they give out errors. Include will continue parsing your script and just shove out an error. Require however will stop the whole script to give you an error. Really it’s all down to what you want.

Include_once and require_once you probably guess only allow you to include the file once. This is not only more secure but stops from silly errors where the file was just included and variables were overwritten halfway through the script. Again they give out the same errors as include and require.

So lets go over one of each!

include('sidebar.php');
include_once('sidebar.php');
require('sidebar.php');
require_once('sidebar.php');

We really are spoiled for choice aren’t we! 😉

Learn PHP: Class Two, Ifs And Elses

Moving on to PHP’s If Else Statements.

Here is one in action:

if ($condition) {
echo 'condition is true';
}

Simple enough? To start with as you can see you first write the statement name, in this case “if”. Then you enclose your condition in brackets, [A condition is essentially a question you ask PHP.] then you add an opening “curly bracket”. The opening curly bracket basically defines the start of the code to execute of the condition of the statement evaluates to true. In this case we are wanting PHP to output the text “condition is true” if the condition is true. Then finally we have a closing curly bracket.
In the above example the entire condition has simply been set to the variable $condition. Therefore what we are asking PHP is does the variable $condition exist, and if it does, does it have a value that is not NULL. [Null = Nothing, zero, zilch] In this case we didn’t actually define the variable $condition therefore the statement will evaluate to false and the code within the statement wont be executed. Therefore the above will output nothing at all. However the following code:

$condition = "Here!"
if ($condition) {
echo 'condition is true';
}

Would output “Condition is True”.

Now if statements are pretty useless on their own! What you really want is if / else statements, which we will look at here!

$condition = 10;
if ($condition == 5) {
echo "condition is 5";
}

Basically here the variable condition is 10. PHP Checks if it is 5. As we all know 10 is not 5, so PHP does nothing. However in this statement:

$condition = 10;
if ($condition == 5) {
echo "condition is 5";
} else if ($condition < 5) {
echo "condition is less than 5";
} else {
echo "condition is $condition";
}

We have an if statement, an if else statement and an else statement.
Basically the code explains it, but the condition is 10. If the condition is 5, PHP will output that it is 5. Otherwise if the condition is less than 5. PHP will output that it is less than five. Lastly, if nothing matches in the if or else if statements PHP will output its else. Saying Condition is 10.

A last sample before we head off.

$condition = "yes";
if ($condition == "no"){
echo "condition is false";
} else if ($condition == "yes"){
echo "condition is true";
} else {
echo "Something happened to the variable";
}

Here you can see that the condition is actually a word. PHP checks it just like it would a number and outputs all the same. Here PHP would output “Condition is True”.

And that’s it for today! Next week we have “arrays” so until then practice! 🙂

Learn PHP: Class One, Echos and Variables

So now that we have done the Prep Class its time to move on to the actual learning!

Echoing:

echo "text here";

OR

echo 'text here';

Simple as that, thats how you get PHP to output some text. Whichever you use is really up to you, there is pros and cons to what you can do with each, you can read about them here.

Comments:
Comments are really important within any programming language, really to tidy up your code and so you remember what each bit does later on. PHP supports two different ways of commenting, C++ Style and Shell style. I will just stick with C++ Style for today

Example’s of echo’ng via C++ Style are as follows:

echo 'Hi'; // Output: Hi
echo 'Hi'; /* Hi */

// Comments out the rest of the line. While /* */ lets you comment as far as you want, just remember to close the comment! If you don’t get me I’ll do a quick example:
This will stop PHP echo’ing “Hi”


/*
echo "Hi";
*/

This however will not.

//
echo "Hi";
//

But this would

//echo “Hi”;
/* style are obviously much easier for commenting out blocks of code. But for just adding a quick comment // style is alot better!

Variables:


$variablename = "Variable One";
$variablename = 'Variable One';
$variablename = 1;

Variables are vital within your programming language, you will use them over and over again! Again, you can use single or double quotes, both with their pros and cons, you can also use numbers, or other variables. I’ll give you a quick example of adding within variables.

$add = 2 + 1;

That variable would add 2 + 1. But how to get what the Variable says? Well you just use echo again!

$add = 2 + 1;
echo $add;

The output of that would be:

3

Nothing more, nothing less.
You can also add variables within variables. As complicated as that sounds its pretty easy. I’ll give you a quick example.


$one = 1;
$two = 2;
$add = $one + $two;
echo $add;

So lets go over what we just learnt with a quick script;

$name = 'Sean'; // My Name
$age = 16 +1; // Seventeen!
$nextage = $age +1; //Age I will be next year.
echo 'Hi my name is ';
echo $name;
echo ' and I am';
echo $age;
echo 'but I will be'
echo $nextage;
echo 'next year!'

Of course that is probably the longest, but easiest way you could do it! The faster way to do it would be:


$name = 'Sean'; // My Name
$age = 16 +1; // Seventeen!
$nextage = $age +1; //Age I will be next year.
echo "Hi my name is $name and I am $age but I will be $nextage next year!”"

That’s defiantly the handiest way to do it! Don’t worry I’ll go a bit more into that in the next lesson! Until then, practice!

Learn PHP: Preparation Time

Nearly two or three times every week I get someone asking me to teach them how to program, many of these are from an online game I help out with called Injustice. Its amazing really that people that there is some hidden secret to coding and that I can just send you a link or say one or two lines and they will be able to code! I’m telling you people, its not magic!!
So instead of repeating myself over and over I’m shoving this article in here! Mainly because of this, secondly because I believe people can learn PHP a little easier than some of the websites make it. So on with the show!

Ok, so to actually learn PHP the best way to do it will be to install Xampp.

You can download Xampp here.
Xampp will install Apache [Webserver] MySQL [Database] and PHP among other things, but that is all we will be using! Once you download the file, run it, its a graphical installer for windows.

For linux users, I’m sure you can work out how to install it! 😉

Once installed start the Apache and MySQL services, the control panel will be in front of you, all you have to do is tick the boxes! Yep thats it, your done installing.

Now, to put files into your “webserver” you will go into C:/Xampp/htdocs/ if you installed it in the default directory. So lets create a folder called project. And put a file called index.php in there. In the index.php file just put the word “Test”. Then all you have to do is go to, http://localhost/project/index.php and if you did everything right you should be looking at a webpage that just says “Test”. There you have it! You are ready to learn PHP!