Tuesday, March 8, 2011

Tuesday 3/8/11


<?php
//adds an element to the beginning of an array

$prices = array(5.95, 10.75, 11.25);
printf("

%s

\n", implode(',', $prices));

array_unshift($prices, 10.85);
printf("

%s

\n", implode(',', $prices));

array_unshift($prices, 3.35, 17.95);
printf("

%s

\n", implode(',', $prices));
?>


New



<?php
function array_insert(&$array, $offset, $new)
{
array_splice($array, $offset, 0, $new);
}
$languages = array('German', 'French', 'Spanish');
printf("
%s
\n", var_export($languages, TRUE));
array_insert($languages, 1, 'Russian');
printf("
%s
\n", var_export($languages, TRUE));
array_insert($languages, 3, 'Mandarin');
printf("
%s
\n", var_export($languages, TRUE));
array_insert($languages, 2, 'Korean');
printf("
%s
\n", var_export($languages, TRUE));

?>

Monday, March 7, 2011

Monday 3/7/11


<?php
function array_display($array, $pre=FALSE)
{
$tag = $pre ? 'pre' : 'p';
printf("<%s>%s\n", $tag, var_export($array, TRUE), $tag);
}
$arr1 = array(1, 2, 3);
$arr2 = array(10, 20, 30);
$arr3 = array(5, 10, 15, 20);

$comb1 = array_merge($arr1, $arr2);
$comb2 = array_merge($arr2, $arr1);
$comb3 = array_merge($arr3, $arr2, $arr1);

array_display($comb1);
array_display($comb2);
array_display($comb3);

$arr4 = array("a", "b", "c", "d");
$arr5 = array(7, 8, 9, 10);
echo "<hr>";
$comb4 = array_merge($arr4, $arr5);
array_display($comb4);
?>


Here is the next tutorial:



<?php
function array_eq_ident($arr1, $arr2)
{
printf("

The two arrays are %sequal.

\n", $arr1 == $arr2 ? '' : "not ");
printf("

The two are arrays are %sidentical.

\n", $arr1 === $arr2 ? '' : "not ");
}

$dogs = array('Lassie' => 'Collie', 'Bud' => 'Sheepdog', 'Rin-Tin-Tin' => 'Alsatian', 'Snoopy' => 'Beagle');

$pups = array('Lassie' => 'Collie', 'Bud' => 'Sheepdog', 'Rin-Tin-Tin' => 'Alsatian', 'Snoopy' => 'Beagle');

$mutts = array('Lassie' => 'Collie', 'Rin-Tin-Tin' => 'Alsatian', 'Bud' => 'Sheepdog', 'Snoopy' => 'Beagle');

print "

\$dogs and \$pups:

\n";
array_eq_ident($dogs, $pups);

print "

\$dogs and \$mutts:

\n";
array_eq_ident($dogs, $mutts);

?>

Sunday, March 6, 2011

Sunday 3/6/11

Just for fun I am going to put here the entire code (so far) for the process form php


<?php
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$phoneNumber = $_POST['phoneNumber'];
$emailAddress = $_POST['emailAddress'];
$contactMethod = $_POST['contactMethod'];
$returnString = "requestContact.php";

$dataArray = array($firstName, $lastName, $phoneNumber, $emailAddress, $contactMethod);
$errorArray = array();


// This function will build a php url that will outline to the contactAdministration PHP form all the errors.
function buildErrorString($returnString, $dataArray, $errorArray) {
$returnString = $returnString . "?";
//use a foreach loop


for ($i=0; $i<count($dataArray); $i++) {
if ($dataArray[$i] != "") {
$name = "value" . $i;
$returnString = $returnString . $name . "=" . $dataArray[$i] . "&";
}
}

foreach ($errorArray as $value) {
$returnString = $returnString . $value . "=" . " Required" . "&";
}

return $returnString;
} //end function buildErrorString


// This function will deposit the data into the notepad file
function depositData($dataArray){
// getCwd() gets the current directory, useful for building the file stream pointer
$current_directory = getCwd();
$file_address = $current_directory . "/files/reqContact.txt";
$outputString = $dataArray[0] . "\t" . $dataArray[1] . "\t" . $dataArray[2] . "\t" . $dataArray[3] . "\t" . $dataArray[4] . "\n";
$fileOpen = fopen($file_address, 'a');
// frwrite() writes the contents of the outputString to the file stream pointed to by the $fileOpen handle
fwrite($fileOpen, $outputString, strlen($outputString));
fclose($fileOpen);


} //end function depositData

for ($i=0; $iif ($dataArray[$i] == "") {
$errorArray[] = "blank" . $i;
}
}



if (count($errorArray) > 0) {
$returnString = buildErrorString($returnString, $dataArray, $errorArray);
} else {
depositData($dataArray);
}

// strips off any extra ampersand off the end of the return string
$returnString = rtrim($returnString, "&");

header("location: $returnString");


?>

Friday, March 4, 2011

Friday 3/4/2011


<?php
$languages = array();
$languages[] = 'German';
$languages[] = 'French';
$languages[] = 'Spanish';
printf("

Languages: %s.

\n", implode(',', $languages));

array_push($languages, 'Mandarin', 'Japanese', 'Korean');
echo "
";
printf("

Languages: %s .

\n", implode(' / ', $languages));


?>

Thursday, March 3, 2011

http://www.killerphp.com/tutorials/object-oriented-php/

<?php
function array_list($array)
{
printf("

(%s)

\n", implode(', ', $array));
}

$arr1 = range(5,11); #integer start/end
array_list($arr1);

$arr2 = range(0, -5);
array_list($arr2);

$arr3 = range(3, 15, 3);
array_list($arr3);

array_List(range(20,0,-5));

array_List(range(2.4, 3.1, .1));

array_List(range('a', 'f'));
?>


Here is another tutorial:


$languages = array('German', 'French', 'Spanish');
printf("

Languages: %s .

\n", implode(', ', $languages));


Here is another tutorial:


$countries_languages = array('Germany' => 'German', 'France' => 'French', 'Spain' => 'Spanish');
echo "Array values: ";
printf("

Languages: %s.

\n",implode(',', array_values($countries_languages)) );
echo "Array keys: ";
printf("

Countries: %s.

\n",implode(',', array_keys($countries_languages)) );


Here is yet another tutorial:


$customers = array(array('first' => 'Bill', 'last' =>'Jones', 'age' => 24, 'state' => 'CA'),
array('first' => 'Mary', 'last' => 'Smith', 'age' => 32, 'state' => 'OH'),
array('first' => 'Joyce', 'last' => 'Johnson', 'age' => 21, 'state' => 'TX'),
);

printf("print_r():
%s
", print_r($customers, TRUE));
printf("var_export():
%s
", var_export($customers, TRUE));

print 'var_dump():
';
var_dump($customers);
print '
';

Wednesday, March 2, 2011

Wednesday 3.2.11


Partial Class Java2sPage
Inherits System.Web.UI.Page

Private Sub DisplayMessage()
Dim i As Integer
For i = 1 To 4
output.Text &= "Welcome to my website
"
Next i
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
output.Text = String.Empty
DisplayMessage()
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
DisplayMessage()
End Sub
End Class


First C# script. Most of it was auto-generated.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblTime.Text = DateTime.Now.ToString("T");
}
}

Tuesday, March 1, 2011

Tuesday, March 1st 2011


<?php
function larger($x, $y) {
if ((!isset($x)) || (!isset($y))) {
return false;
} else if ($x >= $y){
return $x;
} else {
return $y;
}

}

$x = 6;
$y = 7;
$answer = larger($x, $y);
echo "X = $x";
echo "
";
echo "Y = $y";
echo "
";
echo $answer . " is the larger number ";

?>