Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


PHP 101

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Alisterclarke
How do I cheat?
Reputation: 0

Joined: 16 Aug 2007
Posts: 6

PostPosted: Thu Aug 16, 2007 6:00 pm    Post subject: PHP 101 Reply with quote

Ok, I searched the forums for the php basics and din't find anything. So, I'm going to post some basic php.

To start programming in PHP, you'll need to use the tags:


Code:
<? ?>


OR

Code:
<?php ?>


Now that you've learned the tags, its to to print text into a php page:
Code:
<?
echo "Hello! I know where you live";
?>


OR

Code:
<?
print "Hello! I know where you live";
?>


The ; tells the echo command that its done echoing and it can move onto the next line of code. You can use either print or echo to display text.

Variables:
Variables are very useful in PHP. They can store data to later be retrieved. I'm going to show you hopw to define a variable and then retrieve it.

Code:

<?
$variable1 = "This is a variable";
echo "$variable1";
?>


Again we see the ; being used to tell the script to move on to the next line of code.

Use of the 'rand();' function:
The rand function is basically a piece of code that generates a random number. It can only be used for numbers nothing else. Here is an example using the rand function:

Code:

<?
$number = rand(1,1000);
echo "Your lucky number is: $number!":
?>


Again, we use a variable to store the random number. Also we see rand(1,1000);
This tells us to generate a random number between 1 and 1000.

Anyways I hope this helps and I'll be posting more php related things later on.
Back to top
View user's profile Send private message
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Thu Aug 16, 2007 8:48 pm    Post subject: Reply with quote

Also note there is a difference between the two types of quotes.
"$var" translates into (contents of variable $var), this is called interpolation
'$var' means just that, $var.

To join strings/variables together (alternative to using interpolation, or where it would make things clearer) use the period operator (.), known as the concatenation operator.
Code:
echo 'Your lucky number is:' . $number . '!'


Or
Code:
$var = "moo";
$var .= " said the cow"; //.= is similar to +=, a .=b is equivalent to a = a . b



When using PHP for web development (it is possible to use it for other things) it is important not to feel trapped in PHP or HTML, you can flip between either.

Code:
<a href=<? echo $url ?>><? echo $linkname ?></a>


PHP is a language of convenience - if it will make your life easier (at the cost of elegance) PHP probably lets you do it. For example, rather than doing something like
Code:
<? if(a==b) {
echo "<a href='moocow.com'>Mooo</a>\n";
echo "<a href='moocow.com/1'>Mooo</a>\n";
echo "<a href='moocow.com/2'>Mooo</a>\n";
} ?>


It can be easier to look at to do this:
Code:
<? if(a==b): ?> //note the colon
<a href='moocow.com'>Mooo</a>
<a href='moocow.com/1'>Mooo</a>
<a href='moocow.com/2'>Mooo</a>
<? endif; ?>


PHP is quite a fun language, no matter what anyone says!
~nog_lorp

_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites