There were a few problems with it, but it should work as expected now:
Code: Select all
<form method="GET">
<input type="text" name="name" value="Name" /><br />
<input type="text" name="msz" value="Message" />
<input type="submit" name="submit" value="Submit" /><br /><br />
<form>
<?php
$name = (isset($_GET['name'])) ? $_GET['name'] : 'Anonymous';
$msz = (isset($_GET['msz'])) ? $_GET['msz'] : 'Enter a Message';
$smilyChar = array(':p', ':(', ':D', ':X');
$smilyName = array('1.gif', '2.gif', '3.gif', '4.gif');
if (isset($_GET['msz'])) {
for ($i = 0; $i != count($smilyChar); $i++) {
$msz = str_replace($smilyChar[$i], '<img src="smily/' . $smilyName[$i] . '" alt="' . $smilyChar[$i] . '">', $msz);
}
}
echo $msz . ' - ' . $name;
?>
EDIT: Oh "and guide you". First you shouldn't use "$_GET" nor "$_POST" etc, without checking to make sure they are set first. Variables can't be used within single quotes, use double quotes or break out of the single quotes like I do in the script. You didn't need to put the "smily/" in each of the array values, just in the final "$msz" variable. I noticed the unnecessary "$submit" variable, so I removed it. You also had an unnecessary second "$msz" variable, which I also removed. And you didn't make use of the "$name" variable, so I did. Other than that your method was excellent.
