I was doing some coding on my phone when I got this error:
Parse error: syntax error, unexpected '"log.txt"' (T_CONSTANT_ENCAPSED_STRING) in your code on line 15
This is the offending code:
$file = "log.txt";
Note that you have to copy this exactly to get this result. This is because when I retype it:
$file = "log.txt";
I get no error. The two lines are the same, except for one thing: the second space in the line is binary "10100000" in the crashing statement, but "00100000" in the retyped one.
So I suppose my editor screwed up in some mystical way I will probably never discover. But what I don't get is why does this bad character look exactly like a space (as opposed to something else or a �), and why does it cause this particular error as if I didn't properly open my string?
It's a non-breaking space character.
It probably came about as a result of copying the code in from a blog post or from Word, for example.
The interpreter is not able to parse it as a regular space, hence the error.
Related
I did a find-replace and made a mistake which led to the following code being on it's own line.
16;
This caused a lot of issues as it did not produce any errors anywhere and I am very surprised. How is this possibly valid PHP code?
16 is a valid literal. In itself it is a valid expression. 16; is a statement made up of the expression 16 which consists of the single value 16. There's nothing invalid. It simply doesn't do anything.
trying to use a EOD tag to send an email via PHP, heres my code:
The Code is too large, I pasted it on pastebin:
http://pastebin.com/KK3QZx6p
Dreamweaver has an error on line two and the actual browser reports an error on the last line (the script tag that includes jQuery)
I have tried backslashes and all, but the EOD tags are being syntax highlighted, is that maybe the issue?
I basically want to send an email, and the main body I want to be a html email, I know you can use the concatenation, although if there is a way to paste it in using a multiline string and send it, that would be great, although the EOD tag, simply isn't highlighting, like I have done something wrong
Error From Browser: Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$' in /home/a8526867/public_html/index.php
Dreamweaver is erroring on the second line
Indeed, I guess '{' at the last row gives a problem. You might try to escape it. But anyway, I don't think it's a good idea to use js or jquery in an email.
I have an array where I would like to put spaces between the [] like :
$array[South Africa]=array();
But I can't... why this is not possible?
The correct way of doing this is:
$array['South Africa'] = array();
By not placing quotes around strings, PHP will first check if it is a constant, and if not assume you want to specify the string stated (and generate a warning).
This would work without a space (other than the warning and being bad practise) but with the space PHP thinks the string/constant has ended after 'South' and expects an ]. What you have specified will result in a syntax error:
unexpected T_STRING, expecting ']'
I personally would avoid using spaces for names/keys anyway but the above explains the problem you are having if you must do this.
The following 2 lines are my code:
$rank_content = file_get_contents('https://www.championsofregnum.com/index.php?l=1&ref=gmg&sec=42&world=2');
$tmp_ = preg_replace("/.+width=.16.> /Uis", "", $rank_content, 1);
The second line above causes an infinite loop.
In contrary, the following alternatives DO work:
$tmp_ = preg_replace("/.+width=.16.> /Ui", "", $rank_content, 1);
$tmp_ = preg_replace("/[^§]+width=.16.> /Uis", "", $rank_content, 1);
But sadly, they do not give me what I want - both alternatives do not include line breaks within $rank_content.
Also, if I replaced the file_get_contents function with something like
$rank_content = "asdfas\nasdfasdfaswidth=m16m> teststring";
There are no problems either, although \n represents a line break, too, doesn’t it?!
So do I understand it right that RegEx has problems in noticing a String with line breaks in it?
How can I filter a substring of $rank_content (which has multiple lines in it) by removing some lines until something like "width="16" " appears? (Can be seen in the site's source code)
Replace the m modifier with the s modifier. m changes the behaviour of ^ and $, whereas s changes the behaviour of .
That said, you should not be parsing HTML with regex. Seriously. Bad things happen.
I give up on it: It seems the problem is the LENGTH of the haystack variable $rank_content. Its length is about 90,000, while the maximum allowed length for regex match() is about 30,000, so I guess it is the same for regex replace().
Solving this problem would surely be possible, if somebody is interested: Have a look into this link -> PHP preg_match_all limit
I myself am going to solve the problem using another method for reading the contents of a website like HTML Unit or maybe retrieving the site line after line.
When I set variables that include angle brackets (< >) or slashes I keep getting errors like the following (code simplified to focus on error):
Parse error: syntax error, unexpected '>' in D:\hosting\8499439\html\test.php on line 2
<?php
$xml = “<Request>\n”;
?>
I also run into a lot off issues with "unexpected T_String" errors that appear to be related.
I'm running PHP5 on a GoDaddy Windows Server.
What am I doing wrong? (I get the impression I need to to do something so that special characters can be handled in my PHP).
Thanks in advance.
Your quotes are curly quotes, not straight quotes, so PHP runs into an error processing them. A string can only be recognized with straight quotes.
Use the following code:
<?php
$xml = "<Request>\n";
?>
Assuming that you have the same error elsewhere, you can probably do a simple search-and-replace to fix the error: search for one of the curly quotes, replace with a straight quote. Repeat with the other curly quote. Make sure to check for straight quotes that may need to be escaped (for instance, something like "Mary said, "I like this."" would need to be escaped as "Mary said, \"I like this.\"")
mc10 is right.
Additionally I can say, there are only ""(double) and ''(single) quotes in PHP. I suggest you to read about differences between them.
I prefer using single quotes only to keep code clear.