473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Getting a parse error when comparing strings.

Need help in thus script. Trying to create the script that uses comparison operators and functions to compare two strings entered by user. When I add in the info in the script section everything falls apart.
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4.  
  5.  
  6.  
  7. <head>
  8. <title>Compare Strings</title>
  9.  
  10. </head>
  11.  
  12. <body>
  13.  
  14. <h1>Compare Strings</h1><hr />
  15.  
  16.  
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. if (isset($_GET['first_string'] && isset($_GET['second_string'])) {
  4.     $FirstString = $_GET['first_string'];
  5.     $SecondString = $_GET['second_string'];
  6.  
  7.  
  8.     if (FirstString == $SecondString)
  9.         echo "<p>Both Strings are the same</p>";
  10.     else {
  11.     echo "<p>Both have "
  12.         . similar_text($FirstString, $SecondString)
  13.         . " character(s) in common.<br />";
  14.     echo "<p>You must change " . levenshtein($FirstString, $SecondString) ."
  15.     character(s) to make the strings the same.<br />";
  16.  
  17.     }
  18. }
  19.     else
  20.         echo "<p>Enter two strings you want to compare.</p>";
  21.  
  22. ?>
  23.  
Expand|Select|Wrap|Line Numbers
  1. <form action="CompareStrings.php" method="get" enctype="application/x-www-form-urlencoded">
  2. <p>First String <input type="text" name="first_string" size="20" value="<?php if 
  3.  
  4. (!empty($_GET['first_string'])) echo $_GET['first_string'] ?>" /></p>
  5.  
  6. <p>Second String <input type="text" name="second_string" size="20" value="<?php if 
  7.  
  8. (!empty($_GET['second_string'])) echo $_GET['second_string'] ?>" /></p>
  9.  
  10. <p><input type="submit" value="Compare Strings" />
  11.  
  12.  
  13. </form><hr />
  14.  
  15. </body>
  16. </html>
Oct 1 '07 #1
6 4089
code green
1,726 Expert 1GB
When I add in the info in the script section everything falls apart.
Thanks for this excellent detailed analysis.
Never mind. Check this line [PHP]if (FirstString == $SecondString)
echo "<p>Both Strings are the same</p>";[/PHP]
Oct 1 '07 #2
Oh after fixing the spelling error.The error that I have recieved in the beginning is:

Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')'

The form action info works fine without the script info, but when I place in the script that is when I get all kinds of errors.
Oct 1 '07 #3
code green
1,726 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' 
This is followed by the line where the error occured.
And what does this line look like?
If you cannot raise the effort to supply us with accurate info you surely can't expect people to proof read your code.
Oct 1 '07 #4
Sorry about that - I'm new to PHP and really lost. Here is my info again with line numbers. error is:

Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in C:\wamp\www\CSCI 230\Chapter5\CompareStrings.php on line 19
Expand|Select|Wrap|Line Numbers
  1. 1  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. 2  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. 3  <html xmlns="http://www.w3.org/1999/xhtml">
  4. 4
  5. 5
  6. 6
  7. 7  <head>
  8. 8  <title>Compare Strings</title>
  9. 10  </head>
  10. 11
  11. 12  <body>
  12. 13
  13. 14  <h1>Compare Strings</h1><hr />
  14. 15
  15. 16  
Expand|Select|Wrap|Line Numbers
  1. 17  <?php
  2. 18
  3. 19  if (isset($_GET['first_string'] && isset($_GET['second_string'])) {
  4. 20    $FirstString = $_GET['first_string'];
  5. 22    $SecondString = $_GET['second_string'];
  6. 23
  7. 24
  8. 25    if ($FirstString == $SecondString)
  9. 26        echo "<p>Both Strings are the same</p>";
  10. 27    else {
  11. 28    echo "<p>Both have "
  12. 29        . similar_text($FirstString, $SecondString)
  13. 30        . " character(s) in common.<br />";
  14. 31    echo "<p>You must change " . levenshtein($FirstString, $SecondString) ."
  15. 32    character(s) to make the strings the same.<br />";
  16. 33
  17. 34    }
  18. 35  }
  19. 36    else
  20. 37        echo "<p>Enter two strings you want to compare.</p>";
  21. 38 
  22. 39  ?>
Expand|Select|Wrap|Line Numbers
  1. 40
  2. 41  <form action="CompareStrings.php" method="get" enctype="application/x-www-form-urlencoded">
  3. 42  <p>First String <input type="text" name="first_string" size="20" value="<?php if 
  4.  
  5. 43  (!empty($_GET['first_string'])) echo $_GET['first_string'] ?>" /></p>
  6. 44
  7. 45  <p>Second String <input type="text" name="second_string" size="20" value="<?php if 
  8.  
  9. 46  (!empty($_GET['second_string'])) echo $_GET['second_string'] ?>" /></p>
  10. 47
  11. 48  <p><input type="submit" value="Compare Strings" />
  12. 49
  13. 50
  14. 51  </form><hr />
  15. 52
  16. 53  </body>
  17. 54  </html>
  18.  
When I validate it in HTML Validation I get:

Errors and Warnings
Line 41, character 73:
... rst_string" size="20" value="<?php if (!empty($_GET['first_s ...
^Warning: character < is the first character of a delimiter but occurred as data

Line 43, character 75:
... ond_string" size="20" value="<?php if (!empty($_GET['second_ ...
^Warning: character < is the first character of a delimiter but occurred as data

Line 48, character 7:
</form><hr />
^Error: end tag for p omitted; end tags are required in XML for non-empty elements; empty elements require an end tag or the start tag must end with />

Line 45, character 1:
<p><input type="submit" value="Compare Strings" />
^start tag was here
Oct 1 '07 #5
code green
1,726 Expert 1GB
You are missing a bracket on this line.
[PHP]if (isset($_GET['first_string'] && isset($_GET['second_string'])) {[/PHP]
It is easily done.Should be this [PHP]if (isset($_GET['first_string']) && isset($_GET['second_string'])) {[/PHP] But be aware that PHP can behave differently to C when using double conditional statements.
If you ever get strange behaviour wrap each condition in another set of brackets like this [PHP]if ((isset($_GET['first_string'])) && (isset($_GET['second_string']))) {[/PHP]But you should be alright this time
Oct 2 '07 #6
pbmods
5,821 Expert 4TB
Heya, Cutlass.

Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).

Please use CODE tags when posting source code:

[CODE=php]
PHP code goes here.
[/CODE]
Oct 14 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: lawrence | last post by:
If I'm pretty sure there is just one form on the page, can i do this? var myForm = document.forms; If I'm not sure about the form, is it safer to do this? if (document.forms) { var myForm =...
2
by: Andrew Ayers | last post by:
All, I am having a problem with an INSERT onto a table I have created. First off, here is the table: --- CREATE TABLE reg ("customer number" SERIAL PRIMARY KEY, "company name" ...
5
by: Markus Kling | last post by:
"double.Parse(double.MaxValue.ToString())" yields the following Exception: Value was either too large or too small for a Double. at System.Number.ParseDouble(String value, NumberStyles options,...
5
by: Peter Steele | last post by:
We have an application that when it runs in the IDE in debug mode an unhandled exception is occurring in a system header file associated with STL stirngs. The actual statement that crashes is ...
12
by: Dominik Werder | last post by:
Hello! When walking the DOM I check for e.g. obj.nodeName=='DIV' or similar. But this throws a warning in firefox if obj is not a HTMLDivElement. How can you test for HTMLDivElement without...
36
by: Chuck Faranda | last post by:
I'm trying to debug my first C program (firmware for PIC MCU). The problem is getting serial data back from my device. My get commands have to be sent twice for the PIC to respond properly with...
2
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function...
5
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.