Learning PHP and MySQL
Friday, August 18, 2006
Example 11-13 Detecting whether a string is contained in another string
<?php
$password="secretpassword1";
if (strstr($password,"password")){
echo('Passwords cannot contain the word "password".');
}
else {
echo ("Password accepted.");
}
?>
Example 11-13 outputs the following:
Passwords cannot contain the word “password”.
Chapter 11 Code • (0) Comments • (0) Trackbacks • Permalink
Example 11-14 Using several functions together to extract a portion of a string
<?php
$test_string="testing testing Username:Michele Davis";
$position=strpos($test_string,"Username:");
//add on the length of the Username:
$start=$position+strlen("Username:");
echo "$test_string<br>";
echo "$position<br>";
echo substr($test_string,$start);
?>
Chapter 11 Code • (0) Comments • (0) Trackbacks • Permalink
Example 11-15 A simple echo of the timestamp
<?php
$timestamp= time();
echo $timestamp;
?>
Chapter 11 Code • (0) Comments • (0) Trackbacks • Permalink
Example 11-16 Making the date and time appear like we expect
<?php
$timestamp= time();
echo date("m/d/y G.i:s",$timestamp);
?>
This code returns Figure 11-14.
Chapter 11 Code • (0) Comments • (0) Trackbacks • Permalink
Example 11-17 Adding two days to the date
<?php
$timestamp= time();
echo date("m/d/y G.i:s",$timestamp);
$seconds=2*24*60*60;
$timestamp+=$seconds;
echo "<br>new dates is:";
echo date("m/d/y G.i:s",$timestamp);
?>
This outputs:
12/13/05 16.28:32
new dates is:12/15/05 16.28:32
Chapter 11 Code • (0) Comments • (85) Trackbacks • Permalink
Figure 10-03 Text boxes
<form>
<input type="text" name="search" size="10" maxlength="30" />
</form>
This creates the Figure 10-03 in the Learning PHP & MySQL book.
Chapter 10 Code • (0) Comments • (1204) Trackbacks • Permalink
Figure 10-04 A simple form with a text area element
<form>
<label>Suggestion: <textarea name="suggestions" cols="40" rows="5"></textarea>
</label>
<input type="submit" value="Go! />
</form>
This creates the example in Figure 10-04 in the book.
Chapter 10 Code • (0) Comments • (0) Trackbacks • Permalink
Figure 10-05 Checkboxes
<form>
<fieldset>
<label>Italian <input type="checkbox" name="food[]" value="Italian" /></label>
<label>Mexican <input type="checkbox" name="food[]" value="Mexican" /></label>
<label>Chinese <input type="checkbox" name="food[]" value="Chinese"
checked="checked" /></label>
</fieldset>
<input type="submit" value="Go! />
</form>
This code displays Figure 10-05 in the book.
Chapter 10 Code • (0) Comments • (0) Trackbacks • Permalink
Figure 10-06 Radio buttons
<form>
<fieldset>
<label>Italian <input type="radio" name="food" value="Italian" /></label>
<label>Mexican <input type="radio" name="food" value="Mexican" /></label>
<label>Chinese <input type="radio" name="food" value="Chinese"
checked="checked" /></label>
</fieldset>
<input type="submit" value="Go! />
</form>
This code generates the example in Figure 10-06 in the book.
Chapter 10 Code • (12) Comments • (0) Trackbacks • Permalink
Figure 10-09 Selecting Italian and Chinese
<html>
<head>
<title>Using Default Checkbox Values</title>
</head>
<body>
<?php
$food=$_GET[food];
$self=$_SERVER['PHP_SELF'];
if (!empty($food))
{
echo "The foods selected are:<br />";
foreach($_GET[food] as $foodstuf)
{
}
}
else
{
echo ("<form action=\"$self\" ");
echo ('method="get">
<fieldset>
<label>Italian <input type="checkbox" name="food[]" value="Italian" /></label>
<label>Mexican <input type="checkbox" name="food[]" value="Mexican" /></label>
<label>Chinese <input type="checkbox" name="food[]" value="Chinese"
checked="checked" /></label>
</fieldset>
<input type="submit" value="Go!" >
');
}
?>
</body>
</html>
This code displays the graphic Figure 10-09 in the book.
Chapter 10 Code • (19) Comments • (4) Trackbacks • Permalink
Statistics
This page has been viewed 407271 times
Page rendered in 0.3235 seconds
Total Entries: 224
Total Comments: 16
Total Trackbacks: 307338
Most Recent Entry: 09/27/2006 12:39 pm
Most Recent Comment on: 10/26/2007 10:00 am
Total Members: 2
Total Logged in members: 0
Total guests: 10
Total anonymous users: 0
Most Recent Visitor on: 05/19/2012 05:14 am
The most visitors ever was 1103 on 11/20/2007 12:50 pm
