Jump to content

Newbie PHP problem


ninjalemon

Recommended Posts

I'm just starting to learn php, and I set up xampp so I'm using that to test my .php files. I have the file in the right location and php is enabled because it isn't showing me the code, however when my code reads:

 

echo “<p>Random Text</p>”;

print(“<p>You can print with braces</p>”);

print “<p>or without them!</p>”;   

 

The output is:

 

Random Text

 

”; print(“

 

You can print with braces

”); print “

 

or without them!

”;

 

 

Why is it showing the "); part and isn't just displaying what is in the quotations? I'm looking at a youtube video PHP tutorial and typed in exactly what the guy did, but I got this as a result and the person just got the words minus all the " and ) and stuff.

Link to comment
Share on other sites

I don't know what the term is but make sure you're editing with notepad or a program that has vertical quotation marks.

NOT LIKE THIS

echo “<p>Random Text</p>”;
print(“<p>You can print with braces</p>”);
print “<p>or without them!</p>”;    

LIKE THIS

echo "<p>Random Text</p>";
print("<p>You can print with braces</p>");
print "<p>or without them!</p>";

Link to comment
Share on other sites

Fixing both of those problems still just changed my output from displaying the other quote marks to vertical quote marks, so it's just:

 

Random Text

 

"; print "

 

You can print with braces

"; print "

 

or without them!

";

 

 

And I looked at php.net's basic tutorial already, and still  when I do the echo "Hello world!"; , the output I get is

 

Hello World

 

"; ?>

 

 

And I also set the title to be <title><?php echo "Website Title";?></title>

 

And the title just displays as <?php echo"Website Title";?>, and in the tutorial I'm watching, it just comes out as Website Title

Link to comment
Share on other sites

This is my source code in the php file, and again this is copied directly as the tutorial I'm watching says to, and his output is the words without all the extra characters that aren't supposed to be displayed. That's why I'm really confused as to why it's doing this and not what it should be doing

 

<html>
<head>
	<title><?php echo "Website Title";?></title>
</head>
<body>
	<?php

// You can use short tags but it is not recommended doesn’t work in 6
	# You can also comment code like this
	/* Here is a
	multiline comment
	*/

	echo "<p>Random Text</p>";
	print "<p>You can print with braces</p>";
	print "<p>or without them!</p>";     
    </body>
</html>

 

And that produces:

 

Random Text

"; print "

You can print with braces
"; print "

or without them!
";

Link to comment
Share on other sites

You're using a BADDDD editor.

 

For some reason, the PHP engine recognizes the opening quote in your first echo statement, but doesn't see the closing one.

 

My guess is an invalid character.

Link to comment
Share on other sites

I personally use EditPlus however, it is not free. It is however, a great editor and I prefer it over Notepad++.

 

I put your code into my editor and executed it and yes, because you were missing the ?> the script failed. I rewrote the code how I would write it:

 

<html>
<head>
<title>Website Title</title>
</head>
<body>
<?php

echo "<p>Random Text</p>";
print "<p>You can print with braces</p>";
print "<p>or without them!</p>";

?>
</body>
</html>

 

No difference really but it does work! FYI, when I was starting out over ten years ago I found the easiest way to learn was to download open source applications / scripts already written, install them, and then pull them apart to see how they work. The biggest thing that you would want to learn is OOP, Object Oriented Programming. It will help you with rapid development and reusing already written code. Good luck!

Link to comment
Share on other sites

Weird, I believe xyph was correct about the text editor being the issue.

 

I just re-typed the code in Komodo Edit 6.1 and it worked perfectly.

 

Thanks all for the help, I never thought that the text editor would be the problem or that notepad would do something weird like that.

 

 

EDIT: And thanks for the adice sms. I'm familiar with OOP as I took a Java class a couple years ago, and I'll be learning more about it soon since I'll be majoring in CompSci next year in college. I've heard from many people that doing exactly what you described was how they learned, so I'll do the same

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.