<?php /* * Write code to reverse a String. * */ function reverseString($str) { assert(is_string($str)); $start = 0; $end = strlen($str) - 1; while ($start < $end) { $tmp = $str[$start]; $str[$start++] = $str[$end]; $str[$end--] = $tmp; } return $str; } echo reverseString("abcde");
echo "<tr>"; echo "<td>" . $label . "</td><td>" . $waarde . "</td>"; echo "</tr>"; } ?> </table> </article> <article> <h3>Celcius naar Fahrenheit</h3> <?php echo "32 graden celcius is " . toFahrenheit(32) . " graden fahrenheit"; ?> </article> <article> <h3>Is deelbaar door drie?</h3> <?php echo "is 6 deelbaar door drie? "; if (checkDeelDrie(6)) { echo "waar"; } else { echo "nietwaar"; } ?> </article> <article> <h3>Tekst Omkeren</h3> <?php echo "\"Hello World!\" is omgedraait: " . reverseString("Hello World!"); ?> </article>
<?php //use Exception; /* * Write a function to reverse a string. */ function reverseString($randomString) { if (is_string($randomString)) { return strrev($randomString); } else { throw new Exception("The value is no string"); } } echo reverseString("Some Random String");
<title>Document</title> </head> <body> <form action="index.php" method="post"> <p>Enter your string</p> <input type="text" name="userText"><br><br> <input name="submit" type="submit" value="submit"><br><br> </form> </body> </html> <?php function reverseString($text) { $textReverse = strrev($text); echo "Text before: "; echo $text . "<br><br>"; echo "Text before: "; echo $textReverse; } if ($_POST) { if (isset($_POST['userText'])) { $text = $_POST['userText']; } if ($_POST['submit']) { if ($_POST['userText'] == null) { die("Enter text"); } } } reverseString($text);
<?php function reverseString($A) { $arrayA = str_split($A); $reversearray = array_reverse($arrayA); return implode('', $reversearray); } echo reverseString('fuckof');
<html> <head> <?php include "layout.php"; ?> </head> <div class="container"> <div class="content"> <?php toFarhrenheit(20); echo "<br>"; echo reverseString("Hello Jumbo!"); echo "<br>"; echo dividableByThree(3); function toFarhrenheit($celsius) { echo $celsius . " graden celsius = " . ($celsius * 1.8 + 32) . " graden Fahrenheit."; } function dividableByThree($number) { return $number % 3 == 0 ? $number . " is deelbaar door 3!" : $number . " is niet deelbaar door 3!"; } function reverseString($string) { return strrev($string); } ?> <br> <a href="https://github.com/jmoritdev/jmoritphp/blob/master/functions.php">Source code</a> </div>