Jump to content
Larry Ullman's Book Forums

Scripts 7.6 & 7.7 (P.182-185)


Recommended Posts

Hello again. 
 
When I tried out the scripts demonstrating transforming strings and arrays, this is what I got:

 

 

Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.

Error 404 localhost
Apache/2.4.26 (Win32) OpenSSL/1.0.2l PHP/7.1.7

 

Here's my code for list.html:

 

<!doctype html>

<html lang="en">
<head>
   <meta charset="utf-8">
   <title>I Must Sort This Out!</title>
</head>
<body>
<!-- Script 7.6 - list.html -->
<div><p>Enter the words you want alphebetized with each individual word separated by a space:</p>
 
<form action="list/php" method="post">
 
   <input type="text" name="words" size="60">
   <input type="submit" name="submit" value="Alphabetize!">
 
</form>
</div>
</body>
</html>

 

and for list.php:

 

<!doctype html>

<html lang="en">
<head>
   <meta charset="utf-8">
   <title>I Have This Sorted Out</title>
</head>
<body>
<?php // Script 7.7 - list.php
/* This script recieves a string in $_POST['words']. It then turns it into an array, sorts the array alphabetically, and reprints it. */
 
// Address error management, if you want.
 
// Turn the incoming string into an array:
$words_array = explode(' ' , $_POST['words']);
 
// Sort the array:
sort($words_array);
 
// Turn the array back into a string:
$string_words = implode('<br>', $words_array);
 
// Print the results:
print "<p>An alphabetized version of your list is: <br>$string_words</p>";
 
?>
</body>
</html>

 

What am I doing wrong?

Link to comment
Share on other sites

 Share

×
×
  • Create New...