Veronica's code output for Strings:

Strings Revisited

The string is: -- Now is the time for all good men. --note the spaces before and after the string

The length of the string is: 35

Character (ASCII[32]) -- -- is in position 0
Character (ASCII[78]) --N-- is in position 1
Character (ASCII[111]) --o-- is in position 2
Character (ASCII[119]) --w-- is in position 3
Character (ASCII[32]) -- -- is in position 4
Character (ASCII[105]) --i-- is in position 5
Character (ASCII[115]) --s-- is in position 6
Character (ASCII[32]) -- -- is in position 7
Character (ASCII[116]) --t-- is in position 8
Character (ASCII[104]) --h-- is in position 9
Character (ASCII[101]) --e-- is in position 10
Character (ASCII[32]) -- -- is in position 11
Character (ASCII[116]) --t-- is in position 12
Character (ASCII[105]) --i-- is in position 13
Character (ASCII[109]) --m-- is in position 14
Character (ASCII[101]) --e-- is in position 15
Character (ASCII[32]) -- -- is in position 16
Character (ASCII[102]) --f-- is in position 17
Character (ASCII[111]) --o-- is in position 18
Character (ASCII[114]) --r-- is in position 19
Character (ASCII[32]) -- -- is in position 20
Character (ASCII[97]) --a-- is in position 21
Character (ASCII[108]) --l-- is in position 22
Character (ASCII[108]) --l-- is in position 23
Character (ASCII[32]) -- -- is in position 24
Character (ASCII[103]) --g-- is in position 25
Character (ASCII[111]) --o-- is in position 26
Character (ASCII[111]) --o-- is in position 27
Character (ASCII[100]) --d-- is in position 28
Character (ASCII[32]) -- -- is in position 29
Character (ASCII[109]) --m-- is in position 30
Character (ASCII[101]) --e-- is in position 31
Character (ASCII[110]) --n-- is in position 32
Character (ASCII[46]) --.-- is in position 33
Character (ASCII[32]) -- -- is in position 34


The first occurrence of 'l' is in position 22

The first occurrence of 'd' is in position 28

Place the string Now is the time for all good men. into the second index of an array
The string located at the second index of the array is: Now is the time for all good men.
The third character of the Now is the time for all good men. string at the second index of the array is: w

Explode the string  Now is the time for all good men.  into an array
Array ( [0] => [1] => Now [2] => is [3] => the [4] => time [5] => for [6] => all [7] => good [8] => men. [9] => )
Implode the array back into a string: Nowisthetimeforallgoodmen.

Now is the time for all good men. Now is the time for all good men. Now is the time for all good men.

--- Now is the time for all good men. ---

---Now is the time for all good men.---

encrypt of Now is the time for all good men. is: xxRifvB/RfTQM

md5 of Now is the time for all good men. is: 72b5b0f890a59a427c5010d5e21b3bf3

 

CODE FOLLOWS

<?php
include('includes/header.php');

// code
error_reporting(E_ALL);    // set error reporting to all

echo("<h1>Veronica's code output for Strings:</h1>");

echo(
'<h2>Strings Revisited</h2>');

//------------

$hw ' Now is the time for all good men. ';    // <- note spaces before and after the string
echo("The string is: --$hw--note the spaces before and after the string");
echo(
'<br><br>');

$a strlen($hw);    // find the length of the string
echo("The length of the string is: $a");
echo(
'<br><br>');

//------------

for($i 0$i $a$i++)
{
    
$ordord($hw[$i]);
    echo(
"Character (ASCII[$ord]) --$hw[$i]-- is in position $i");     // show the characters within the string
    
echo('<br>');
}
echo(
'<br><br>');


//------------

$b stripos($hw'l');        // where is the first 'l' in the string
echo("The first occurrence of 'l' is in position $b");
echo(
'<br><br>');

//------------

$b stripos($hw'd');        // where is the first 'd' in the string
echo("The first occurrence of 'd' is in position $b");
echo(
'<br><br>');


//------------

$b = array();        // create an array
echo("Place the string $hw into the second index of an array");
echo(
'<br>');
$b[2] = $hw;        // place ' Hello World ' in index 2
echo("The string located at the second index of the array is: $b[2]");
echo(
'<br>');
echo(
"The third character of the $hw string at the second index of the array is: " $b[2][3] );
echo(
'<br><br>');

//------------

$c = array();        // create an array
$c explode(' '$hw);    // explode the string into an array
echo('<pre>');
echo(
"Explode the string $hw into an array<br>");
print_r($c);        // show the array
echo('</pre>');

$d implode(''$c);    // implode the array back into a string
echo("Implode the array back into a string: $d");    // show the string
echo('<br><br>');

//------------

echo(str_repeat($hw3));    // repeat Hello World three times
echo('<br><br>');

//------------

echo("---$hw---");        // show the spaces at the start and end of the string
echo('<br><br>');
$b trim($hw);        // remove the spaces at the start and end of the string
echo("---$b---");
echo(
'<br><br>');

//------------

$salt "xx";
$f crypt($hw$salt);        // encrypt the string
echo("encrypt of $hw is: $f");
echo(
'<br><br>');

$f md5($hw);        // md5 the string
echo(" md5 of $hw is: $f");
echo(
'<br><br>');

include(
'includes/footer.php');
?>