help with strings

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

Post Reply
p_sha85
Forum Commoner
Posts: 30
Joined: Sat Mar 21, 2009 1:55 pm

help with strings

Post 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>
 
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Re: help with strings

Post 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.
p_sha85
Forum Commoner
Posts: 30
Joined: Sat Mar 21, 2009 1:55 pm

Re: help with strings

Post 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> 
 
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Re: help with strings

Post 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.
p_sha85
Forum Commoner
Posts: 30
Joined: Sat Mar 21, 2009 1:55 pm

Re: help with strings

Post by p_sha85 »

Oops, I forgot to take out the "input type" thing... I will try the code again. Thanks!
Post Reply