Archive for the ‘ PHP ’ Category

Switch Statement

A PHP switch statement is almost like an IF statement except it is good to use a switch statement when you want to compare many results on the same variable.

Example with integer.

<?php
switch?($i):
case
0:
echo
"i = 0";
break;
case
1:
echo
"i = 1";
break;
case
2:
echo
"i = 2";
break;
default:
echo
"i?is?not?equal?to?0,?1?or?2";
endswitch;
?>

Example with a string.

<?php
switch?($i)?{
case
"eagle:
echo
"i?is eagle";
break;
case
"hawk":
echo
"i?is hawk";
break;
case
"blue jay":
echo
"i?is blue jay";
break;
}
?>

How do I create PHP Functions()

There are over 700 functions available in php and below I will show you how to create you own function.? Functions all start with the word function(). Here are some things to remember

  • name your functions based on what a function does
  • { start your function
  • put your code
  • } end your function
  • call your function

<?php function fullname($firstname){ // Start your function with an appropriate function name

// Put your code

$last_name = “Smith”;
$full_name= $first_name . ” ” . $last_name;
return $full_name;

} // end your function

<?PHP echo fullname(Joe); ?> //Calling this function will display Joe Smith

So you want to separate your string using explode or join your string using implode in vb.net? Explode/implode are functions of the php environment and do not exist in asp.net therefore you must use the split() function to get your results for explode and join() for implode.

Split() Example

mystring = “hello;sir;how are you”;

arrayData=mystring.Split(mystring,”;”)

Result
arrayData(0) would equal “hello”
arrayData(1) would equal “sir”
arrayDate(2) would equal “how are you”

Join() Example

Dim JoinArray(3)

JoinArray(0) = "Welcome"
JoinArray(1) = "to"
JoinArray(2) = "Web Infinite"

Dim strSentence as String
strSentence = join(JoinArray)

Result
strSentence would equal to “Welcome to Web Infinite”

Post PHP code in WordPress

Here?s a great website that will transform PHP into html for pasting into WordPress, forums, or anywhere. It?s here.