Categories
PHP

Simple PHP User Input Sort

I’ve been doing more programming challenges, and thought I would post my results here again. The first one, sorts user input. So if a user inputs a series of integers, they’ll be echoed out in order. It also does strings. The  sort is taking place with the PHP sort() function.

The second challenge was to write out the ’99 bottles of beer on the wall’ song. Both really simple challenges, but I thought it wouldn’t hurt to post them here anyways.

Sort
https://www.reddit.com/r/dailyprogrammer/comments/pu1rf/2172012_challenge_9_easy/

And here are my results:

<!DOCTYPE html>
<html>
<head>
	<style>
		.content {
			text-align: center;
			margin: 50px;
		}
	</style>
</head>
<body>
	<div class="content">
		<form action="sort.php" method="post" >
			<label for="inputs">#'s: </label>
			<input type="text" name="text1" id="text1"><br><br>
			<input type="submit" name="submit" value="Submit">
		</form>
		<?php
			if(!empty($_POST["text1"])) {
				$ints = explode(" ", $_POST["text1"]);
				sort($ints);
				foreach ($ints as $key => $value) {
					echo $value . "<br>";
				}
			}
		?>
	</div>
</body>
<footer>
</footer>
</html>




99 bottles
https://www.reddit.com/r/dailyprogrammer/comments/pserp/2162012_challenge_8_easy/

With the solution here:

<!DOCTYPE html>
<html>
<head>
	<style>
		.content {
			text-align: center;
			margin: 50px;
		}
	</style>
</head>
<body>
	<div class="content">
		<?php
			$bottles = 99;
			while ($bottles > 1) {
				echo $bottles . " bottles of beer on the wall, " . $bottles . " bottles of beer, take one down and pass it around " . --$bottles ." bottles of beer on the wall. ";
			}
			echo $bottles . " bottle of beer on the wall, " . $bottles . " bottle of beer, take one down and pass it around " . --$bottles ." bottles of beer on the wall. ";
		?>
	</div>
</body>
<footer>
</footer>
</html>




 

By Dylan Hildenbrand

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.