PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
p_sha85
Forum Commoner
Posts: 30 Joined: Sat Mar 21, 2009 1:55 pm
Post
by p_sha85 » Thu Apr 23, 2009 10:44 pm
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>
liljester
Forum Contributor
Posts: 400 Joined: Tue May 20, 2003 4:49 pm
Post
by liljester » Thu Apr 23, 2009 10:48 pm
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.
p_sha85
Forum Commoner
Posts: 30 Joined: Sat Mar 21, 2009 1:55 pm
Post
by p_sha85 » Thu Apr 23, 2009 10:59 pm
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>
liljester
Forum Contributor
Posts: 400 Joined: Tue May 20, 2003 4:49 pm
Post
by liljester » Fri Apr 24, 2009 11:20 am
you didnt fix it.. you cannot have *ANY* html elements inside your <?php ?> tags. you can only have php code inside of <?php ?> tags.
p_sha85
Forum Commoner
Posts: 30 Joined: Sat Mar 21, 2009 1:55 pm
Post
by p_sha85 » Fri Apr 24, 2009 2:37 pm
Oops, I forgot to take out the "input type" thing... I will try the code again. Thanks!