473,563 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting a parse error when comparing strings.

5 New Member
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 4101
code green
1,726 Recognized Expert Top Contributor
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
cutlass
5 New Member
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 Recognized Expert Top Contributor
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
cutlass
5 New Member
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\CSC I 230\Chapter5\Co mpareStrings.ph p 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 Recognized Expert Top Contributor
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 Recognized Expert Expert
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
7978
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 = document.forms; // more code here........ }
2
2036
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" VARCHAR(50) NULL, address VARCHAR(100) NULL, city VARCHAR(50) NULL, state VARCHAR(2) NULL, zip VARCHAR(50) NULL, phone VARCHAR(50) NULL,
5
5645
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, NumberFormat Info numfmt) at System.Double.Parse(String s, NumberStyles style, NumberFormatInfo info) at System.Double.Parse(String s) ...
5
2691
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 return ::memcmp(_First1, _First2, _Count); On inspecting these variables, the strings are in fact equal when the exception occurs and _Count is the...
12
13400
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 throwing any warning, notice or something? Thanks! Dominik Werder
36
3180
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 the needed data. Any ideas? Here's the code in question, see any reason why a command would not trigger the 'kbhit' the first time a serial command...
2
3373
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 checkInteger(&$value, $checks) { $err = ''; if (!is_numeric($value) || (floatval($value) != intval($value))) { $err .= 'Input must be an integer. ';
5
64603
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 article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts,...
1
64041
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 article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts,...
0
7664
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6250
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.