Page 1 of 1

PHP is not parsing correctly, cut & paste

PostPosted: 22. March 2012 05:24
by Kyp
I've redefined the problem, please see my notes below

I'm running Apache 1.77, PHP 5.3.8 and obtain parsing errors on the simplest of variable assignments.

Code: Select all
<?php
$quantity = 30;
$price = 119.95;
$taxrate = .05;

?>


results in:

Parse error: syntax error, unexpected T_DNUMBER in C:\xampp\htdocs\myphp\NumbersClip.php on line 3


Ok, perhaps someone can explain this to me:
The code not working is a cut and paste, not just here but into my php file. However, if I type the code into my notepad++ directly and run it then it works. I've even tried to run after saving in a 'cut and paste' to a windows notebook and I get parsing errors. I've tried cut 'n' paste of different code from different sources and get parsing errors, also on assignment variables. Anyone else had such problems ? I've even highlighted the code to look for training spaces, but find none.

Re: New Install and PHP is not parsing correctly

PostPosted: 23. March 2012 01:46
by hackattack142
I don't write PHP but I am going to take a guess and say a number should always start with a number. A period is not a number so you could try putting $taxrate = 0.05;

Re: New Install and PHP is not parsing correctly

PostPosted: 23. March 2012 06:25
by Altrea
The full expression for a double value in php is
http://www.php.net/manual/en/language.types.float.php wrote:
Code: Select all
([0-9]*[\.][0-9]+) | ([0-9]+[\.][0-9]*)


so, there can be a leading zero, but it don't have to (presuming there are coming digits after the dot).
By now i have no idea why this error occurs on your machine.

I will try to do some Bugtracking on different machines.

best wishes,
Altrea

Cut and Paste to PHP not parsing

PostPosted: 28. March 2012 01:56
by Kyp
I posted the problem here:
http://community.apachefriends.org/f/viewtopic.php?f=16&t=50201

and received a few replys before I realized that the problem needed to be redefined. Apparantly when I type my code directly, I have no parsing errors. However, a cut & paste of correct code is not being parsed. I am using Notepad++, encoded in ANSI for php code editing.

Re: PHP is not parsing correctly, cut & paste

PostPosted: 28. March 2012 02:04
by Sharley
To eliminate a Notepad++ issue try using Windows Notepad and see if you still have this copy and paste issue.

If Notepad works then it has to be either a setting (perhaps BOM) in Notepad++ or...

...where are you copying the code from as there may be hidden formatting code tags that are also being copied, usually if you copy from a web page this can occur.

Best to use the web page source code view to see what you are actually copying.