Jump to content

Hello I need some assistance with an HTML project on line 9 it says there is an error but from what I can see there is none

DOCTYPE!>
<html> 
<head> 
<title>Compare Strings</title>
<h1>Compare Strings</h1><hr />
<?php
$firstString = "Geek2Geek";
$secondString = "Gezzer2Geek"
 if (!empty($firstString) && !empty($secondString) {
 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>Either the \$firstString variable or
 the \$secondString variable does not
 contain a value so the two strings cannot
 be compared.
 </p>";

 

Link to comment
https://linustechtips.com/topic/969480-assistance/
Share on other sites

Link to post
Share on other sites

it looks like you're missing a parenthesis for the if statement

if (!empty() && !empty()) {
                        ^ this one

also, you can use the code tool in the editor to add code in a more readable way here on the forum

Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to comment
https://linustechtips.com/topic/969480-assistance/#findComment-11729742
Share on other sites

Link to post
Share on other sites

ok now it saying error in else clause in line 12

<DOCTYPE!>
<html> 
<head> 
<title>Compare Strings</title>
<h1>Compare Strings</h1><hr />
<?php
$firstString = "Geek2Geek";
$secondString = "Gezzer2Geek";
if (!empty($firstString) && !empty($secondString)) {
 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>Either the \$firstString variable or
 the \$secondString variable does not
 contain a value so the two strings cannot
 be compared.
 </p>";

error in line 12 with else

 

Link to comment
https://linustechtips.com/topic/969480-assistance/#findComment-11729929
Share on other sites

Link to post
Share on other sites

 if ($firstString == $secondString){
 echo "<p>Both strings are the same.</p>";
}
  else {

 

but you'll have another error, so I fixed it too.

 

Full working script:

<DOCTYPE!>
<html> 
<head> 
<title>Compare Strings</title>
<h1>Compare Strings</h1><hr />
<?php
$firstString = "Geek2Geek";
$secondString = "Gezzer2Geek";
if (!empty($firstString) && !empty($secondString)) {
 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>Either the \$firstString variable or
 the \$secondString variable does not
 contain a value so the two strings cannot
 be compared.
 </p>";
}
?>


  

 

Link to comment
https://linustechtips.com/topic/969480-assistance/#findComment-11729976
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×