Beginning PHP Problems - Basic Function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rift
Forum Newbie
Posts: 2
Joined: Wed Sep 10, 2008 5:08 pm

Beginning PHP Problems - Basic Function

Post by rift »

I'm just starting out with PHP, so I'm sure this is a very basic issue, and I'm just overlooking something. Actually the following PHP code is from a function example in a beginner book that I'm reading:

Code: Select all

<html>
<head>
<title>Create a User Function</title>
<?php
function myFunction($company) {
print("<p>Welcome to $company</p>");
}
?>
</head>
<body>
<h3>Start</h3>
<?php
$company = “Acme Auto”;
myFunction($company);
?>
<h3>End</h3>
</body>
</html>
When I create a PHP document, insert this code, and try to run it, I get a "Parse error: syntax error, unexpected T_STRING" error on the line that assigns "Acme Auto" to the $company variable.

Any idea what I might be doing wrong?

Thanks.
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: Beginning PHP Problems - Basic Function

Post by Ziq »

You're try to set not correct value in variable $company.

Code: Select all

$company = “Acme Auto”;
Use quotes

Code: Select all

 
$company = "Any text";
//or
$company = 'Any text';
 
rift
Forum Newbie
Posts: 2
Joined: Wed Sep 10, 2008 5:08 pm

Re: Beginning PHP Problems - Basic Function

Post by rift »

Oh wow. I tried using single quotes as you suggested, and it worked. Then out of curiosity, I tried going back and manually entering the double-quotes (I originally copied the code from a PDF), and it worked that way, too. It looks like the formatting originally used in the document for the quotes somehow confused the browser, so re-typing it cured the problem. Thanks for your help, Ziq!
Post Reply