Online
 
Friday, 09 January 2009
 
 
More article:
Related Content:

Implementing Arrays
 
Article Index
Implementing Arrays
Page 2
Page 3
Page 4
Page 5
Page 6
Page 7
Page 8
Page 9
Page 10
 

With all the initialization complete, you randomize your cryptogram lookup table using the shuffle() function discussed earlier and begin encoding your cryptogram (see ):

Listing 2.18. A Cryptogram Generator Using PHP Arrays (Part 2)
$encoded = "";

/* Cycle through each character of the message to encode */
for($i = 0; $i < strlen($message); $i++) {

$char = $message[$i];

/* Determine if the current character is encodable
by searching for it in the $cryptogram lookup table */
if(!in_array($char, $cryptogram)) {

/* if character is not encodable, copy straight to
the encoded string */
$encoded .= $char;

} else {

/* if the character is encoded, replace it with the
matching character from $cryptogram */
$encoded .= $cryptogram[$alphabet[$char]];

}

}

echo $encoded;
?>

NOTE

Although not arrays, a string within PHP can behave like an array; it allows the developer to access a single character from the string by referencing it using the square-bracket syntax shown in . Note that although strings can behave as arrays, they cannot be used with array manipulation statements, such as foreach(), or array functions.



Tags: Add more tags...,
This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a comment. Tags: Simple PHP, Pear, Easy PHP, PHP Tutorial, PHP MySQL, XSLT, Sap Tutorial, CSS Tutorial, XSL FO Java, SQL Tutorial.
Users' Comments (0)

Comment an article
  Name
  E-mail
   Title
Available characters: 4000
 Notify me of follow-up comments
This image contains a scrambled text, it is using a combination of colors, font size, background, angle in order to disallow computer to automate reading. You will have to reproduce it to post on my homepage
Enter what you see:

No comment posted

Mobile Wallpaper 41
Statistic


Last Post

 
Top! Top!