ninjalemon Posted May 6, 2011 Share Posted May 6, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235721-newbie-php-problem/ Share on other sites More sharing options...
Drummin Posted May 6, 2011 Share Posted May 6, 2011 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/235721-newbie-php-problem/#findComment-1211589 Share on other sites More sharing options...
incubi1 Posted May 6, 2011 Share Posted May 6, 2011 One of your print line is incorrect why the () ? Good place to start http://php.net/ Quote Link to comment https://forums.phpfreaks.com/topic/235721-newbie-php-problem/#findComment-1211591 Share on other sites More sharing options...
ninjalemon Posted May 6, 2011 Author Share Posted May 6, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235721-newbie-php-problem/#findComment-1211593 Share on other sites More sharing options...
incubi1 Posted May 6, 2011 Share Posted May 6, 2011 NP show me all your source of your php test file. incubi Quote Link to comment https://forums.phpfreaks.com/topic/235721-newbie-php-problem/#findComment-1211595 Share on other sites More sharing options...
ninjalemon Posted May 6, 2011 Author Share Posted May 6, 2011 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! "; Quote Link to comment https://forums.phpfreaks.com/topic/235721-newbie-php-problem/#findComment-1211598 Share on other sites More sharing options...
incubi1 Posted May 6, 2011 Share Posted May 6, 2011 When I run that I get an error in my log that says [06-May-2011 12:18:09] PHP Parse error: syntax error, unexpected '<' in test.php on line 17 Check where you have and don't have the <?php and ?> incubi Quote Link to comment https://forums.phpfreaks.com/topic/235721-newbie-php-problem/#findComment-1211602 Share on other sites More sharing options...
ninjalemon Posted May 6, 2011 Author Share Posted May 6, 2011 I just noticed I did forget the ?> at the end of the php, however that just changes the output result to: Random Text "; print " You can print with braces "; print " or without them! "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/235721-newbie-php-problem/#findComment-1211607 Share on other sites More sharing options...
xyph Posted May 6, 2011 Share Posted May 6, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235721-newbie-php-problem/#findComment-1211609 Share on other sites More sharing options...
ninjalemon Posted May 6, 2011 Author Share Posted May 6, 2011 I did all of this in notepad because I just started attempting to do some php. Is there any suggestions on an editor I should use, and I'll see if it fixes my problem? Quote Link to comment https://forums.phpfreaks.com/topic/235721-newbie-php-problem/#findComment-1211613 Share on other sites More sharing options...
incubi1 Posted May 6, 2011 Share Posted May 6, 2011 After fixing the ?> I get the correct results so it works I would check the PHP logs and the Apache log if you use Apache. Have you ever ran a script that worked? Can you post the output from phpinfo.php notepad++ http://notepad-plus-plus.org/ incubi Quote Link to comment https://forums.phpfreaks.com/topic/235721-newbie-php-problem/#findComment-1211616 Share on other sites More sharing options...
smsmarketeers Posted May 6, 2011 Share Posted May 6, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/235721-newbie-php-problem/#findComment-1211622 Share on other sites More sharing options...
ninjalemon Posted May 6, 2011 Author Share Posted May 6, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235721-newbie-php-problem/#findComment-1211625 Share on other sites More sharing options...
incubi1 Posted May 6, 2011 Share Posted May 6, 2011 Happy MS Windowing Good Luck Quote Link to comment https://forums.phpfreaks.com/topic/235721-newbie-php-problem/#findComment-1211627 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.