Tuesday, January 11, 2011

Tuesday 1/11/10


<?php
function strcat($left, $right) {
return $left . $right;
}

$first = "This is a ";
$second = " complete sentence!";
echo strcat($first, $second);
?>


Here is another tutorial

<html>
<body>
<?php
$d = date("D");
if ($d == "Fri")
echo "Have a nice weekend!";
elseif ($d == "Sun")
echo "Have a nice Sunday!";
else
echo "Have a nice day!";
?>
</body>
</html>

Here is the last tutorial of the day on PHP, next I will work on JavaScript


<html>
<head>
<title>String Functions</string>
</head>
<body>
<?php
$firstString = "The quick brown fox ";
$secondString = " jumped over the lazy dog.";
?>
<?php
$thirdString = $firstString;
$thirdString .= $secondString;
echo $thirdString;
?>
<br />
Length: <?php echo strlen($thirdString); ?><br />
Find: <?php echo strstr($thirdString, "brown"); ?><br />
Replace by String: <?php echo str_replace("quick", "super-fast", $thirdString); ?>


</body>
</html>


Here is a JavaScript Tutorial



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function showStrings()
{
var cookbookString = new Array();

cookbookString[0] = "Joe's Cooking Book";
cookbookString[1] = "Sam's Cookbook";
cookbookString[2] = "JavaScript Cookbook";
cookbookString[3] = "JavaScript cookbook";
cookbookString[4] = "Cooking with Gas";

// search pattern

// When creating the regular expression, use the ignore case flag (i)
var pattern = /Cook.*Book/i;

for (var i = 0; i < cookbookString.length; i++)
{
alert(cookbookString[i] + " " + pattern.test(cookbookString[i],i));
}
}
</script>
</head>
<body onload="showStrings()">
</body>
</html>


Here is another tutorial, dealing with social security numbers



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>2.3 Validating a Social Security Number</title>
<script type="text/javascript">
// The numbers in a Social Security number can be matched with the digit special character (\d)
function checkNumber()
{
var ssn = document.getElementById("pattern").value;
var pattern = /^\d{3}-\d{2}-\d{4}$/;
if (ssn.match(pattern))
alert("OK");
else
alert("Not OK");
}
</script>
</head>
<body>
<form>
<input type="text" id="pattern">
<BR>
<input type="submit" id="submitButton" onclick="checkNumber()"></input>
</form>
</body>
</html>

No comments: