strrev 


string apg

REVERSE a string.



<?php

str str_shuffle 
str $str )


where,

$str The STRING to be reversed

?>
 

$str


The input STRING.



  1 EXERCISE   

<?php

$str01 
"There's no smoke without fire.";

$revd01 strrev($str01);

echo 
"Given string:<br>$str01<br><br>Inverse shuffled:<br>$revd01";

?> 

  2 EXERCISE   

<?php

$str02 
"abc1230 ãçÇóÒ k789";

$revd02 strrev($str02);

echo 
"Given string:<br>$str02<br><br>Inverse shuffled:<br>$revd02";

?> 

  3 EXERCISE   

<?php

    $i 
0;
    
$str '';

    while (
$i<256) {
        
$str .= chr($i++);
    }

    echo 
"$str<br><br>";
    
var_dump(md5(strrev($str)));
    echo 
"<br><br>";
    
var_dump(strrev(NULL));
    echo 
"<br><br>";
    
var_dump(strrev(""));
    
?>

  4 EXERCISE   

<?php

echo "Testing strrev() : basic functionality.<br><br>- - - - - - -<br>";

function 
str_rev($one) {
    echo 
"Given value:<br>$one<br><br>Returned value: ";
    
var_dump(strrev($one));
    echo 
'<br>- - - - - - -<br>';
}  

$heredoc = <<<EOD
Hello, world
EOD;

//regular string
str_rev("Hello, World");
str_rev('Hello, World');

//single character
str_rev("H");
str_rev('H');

//string containing simalr chars
str_rev("HHHHHH");
str_rev("HhhhhH");

//string containing escape char
str_rev("Hello, World\n");
str_rev('Hello, World\n');

//heredoc string
str_rev($heredoc);

?>

  5 EXERCISE   

<?php

/* Testing strrev() function with various 
   double quoted strings for 'str' */

echo "Testing strrev() : 
             with various double quoted strings.<br>"
;
             
$str "Hiiii";

$strings = array(
  
//strings containing escape chars
  
"hello\\world",
  
"hello\$world",
  
"\ttesting\ttesting\tstrrev",
  
"testing\rstrrev testing strrev",
  
"testing\fstrrev \f testing \nstrrev",
  
"\ntesting\nstrrev\n testing \n strrev",
  
"using\vvertical\vtab",

  
//polyndrome strings
  
"HelloolleH",
  
"ababababababa",

  
//numeric + strings
  
"Hello123",
  
"123Hello",
  
"123.34Hello",
  
"Hello1.234",
  
"123Hello1.234",

  
//concatenated strings
  
"Hello".chr(0)."World",
  
"Hello"."world",
  
"Hello".$str,

  
//strings containing white spaces
  
"              h",
  
"h              ",
  
"      h        ",
  
"h  e  l  l  o  ",

  
//strings containing quotes
  
"\hello\'world",
  
"hello\"world",

  
//special chars in strings
  
"t@@#$% %test ^test &test *test +test -test",
  
"!test ~test `test` =test= @test@test.com",
  
"/test/r\test\strrev\t\\u /uu/",

  
//only special chars
  
"!@#$%^&*()_+=-`~"
);

$count 1;
for( 
$index 0$index count($strings); $index++ ) {
  echo 
"<br><br>Iteration: $count<br>";
  
var_dumpstrrev($strings[$index]) );
  
$count ++;
}

?>

  6 EXERCISE   

<?php

/* Testing strrev() function with 
   various single quoted strings 
   for 'str' */

echo "Testing strrev() : 
          with various single quoted strings.<br>"
;
          
$str 'Hiiii';

$strings = array(
  
//strings containing escape chars
  
'hello\\world',
  
'hello\$world',
  
'\ttesting\ttesting\tstrrev',
  
'testing\rstrrev testing strrev',
  
'testing\fstrrev \f testing \nstrrev',
  
'\ntesting\nstrrev\n testing \n strrev',
  
'using\vvertical\vtab',

  
//polyndrome strings
  
'HelloolleH',
  
'ababababababa',

  
//numeric + strings
  
'Hello123',
  
'123Hello',
  
'123.34Hello',
  
'Hello1.234',
  
'123Hello1.234',

  
//concatenated strings
  
'Hello'.chr(0).'World',
  
'Hello'.'world',
  
'Hello'.$str,

  
//strings containing white spaces
  
'              h',
  
'h              ',
  
'      h        ',
  
'h  e  l  l  o  ',

  
//strings containing quotes
  
'\hello\'world',
  
'hello\"world',

  
//special chars in string
  
't@@#$% %test ^test &test *test +test -test',
  
'!test ~test `test` =test= @test@test.com',
  
'/test/r\test\strrev\t\u /uu/',

  
//only special chars
  
'!@#$%^&*()_+=-`~'
);

$count 1;
for( 
$index 0$index count($strings); $index++ ) {
  echo 
"<br><br>Iteration $count<br>";
  
var_dumpstrrev($strings[$index]) );
  
$count ++;
}

?>

  7 EXERCISE   

<?php

/* Testing strrev() function 
   with heredoc strings for 'str' */

echo "Testing strrev() function: 
              with heredoc strings.<br>"
;

$multi_line_str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;

$special_chars_str = <<<EOD
Ex'ple of h'doc st'g, contains
$#%^*&*_("_")!#@@!$#$^^&*(special)
chars.
EOD;

$control_chars_str = <<<EOD
Hello, World\n
Hello\0World
EOD;

$quote_chars_str = <<<EOD
it's bright o'side
"things in double quote"
'things in single quote'
this\line is /with\slashs
EOD;

$blank_line = <<<EOD

EOD;

$empty_str = <<<EOD
EOD;

$strings = array(
  
$multi_line_str,
  
$special_chars_str,
  
$control_chars_str,
  
$quote_chars_str,
  
$blank_line,
  
$empty_str
);

$count 1;
for( 
$index 0$index count($strings); $index++ ) {
  echo 
"<br><br>Iteration $count<br>";
  
var_dumpstrrev($strings[$index]) );
  
$count ++;
}

?>