Page 1 of 1

Beginning PHP Problems - Basic Function

Posted: Wed Sep 10, 2008 5:20 pm
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.

Re: Beginning PHP Problems - Basic Function

Posted: Wed Sep 10, 2008 5:34 pm
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';
 

Re: Beginning PHP Problems - Basic Function

Posted: Wed Sep 10, 2008 5:44 pm
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!