Page 1 of 1

help with strings

Posted: Thu Apr 23, 2009 10:44 pm
by p_sha85
Hi.. I have this code and it's giving me a few different errors but I'm not sure exactly what is wrong and what is right in it. Can someone help me out?? Thanks!

Code: Select all

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Compare Strings</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Compare Strings</h1><hr />
<?php
<form action="CompareStrings.php" method="get"
enctype="application/x-www-form-urlencoded">
<p>First String <input type="text" name="first_string" size="20"
$_GET['first_string'] value="<?php if (!empty($_GET['first_string'])) echo $_GET['first_string'] ?>" /></p>
<p><input type="submit" value="Compare Strings" />
</form><hr />
?>
</body>
</html>
 

Re: help with strings

Posted: Thu Apr 23, 2009 10:48 pm
by liljester
you cannot have html tags inside of your <?php ?> tags... you can only have php inside <?php ?> tags.

Code: Select all

<?php
<form action="CompareStrings.php" method="get" enctype="application/x-www-form-urlencoded">
?>
will cause a parse error.

Re: help with strings

Posted: Thu Apr 23, 2009 10:59 pm
by p_sha85
Okay, I fixed that part but now I'm getting another parse error which says: Parse error: syntax error, unexpected '<' in /home/a5936353/public_html/CompareStrings.php on line 13 I don't see any unexpected '<' on line 13... please let me know what I'm doing wrong. Thanks!

Here is the revised code:

Code: Select all

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Compare Strings</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Compare Strings</h1><hr />
<form action="CompareStrings.php" method="get"
enctype="application/x-www-form-urlencoded">
</form><hr />
<?php
<p>First String <input type="text" name="first_string" size="20"
$_GET['first_string'] value="<?php if (!empty($_GET['first_string'])) echo $_GET['first_string'] ?>" /></p>
<p>Second String <input type="text" name="second_string" size="20" value="<?php if (!empty($_GET['second_string'])) echo $_GET['second_string'] ?>" /></p>
<p><input type="submit" value="Compare Strings" />
 
if (isset($_GET['first_string']) && isset($_GET['second_string'])) {
     $FirstString = $_GET['first_string'];
     $SecondString = $_GET['second_string'];
     if ($FirstString == $SecondString)
      echo "<p>Both strings are the same.</p>";
     else {
      echo "<p>Both strings have "
         . similar_text($FirstString, $SecondString)
         . " character(s) in common.<br />";
      echo "<p>You must change " . levenshtein($FirstString, $SecondString) . " character(s) to make the strings the same.<br />";
     }
}
else
     echo "<p>Enter two strings you want to compare.</p>";
?>
</body>
</html> 
 

Re: help with strings

Posted: Fri Apr 24, 2009 11:20 am
by liljester
you didnt fix it.. you cannot have *ANY* html elements inside your <?php ?> tags. you can only have php code inside of <?php ?> tags.

Re: help with strings

Posted: Fri Apr 24, 2009 2:37 pm
by p_sha85
Oops, I forgot to take out the "input type" thing... I will try the code again. Thanks!