making close button with java script in php - php

For closing a <div>, I use onclick="this.parentNode.style.display='none';" (in HTML) and it works. But in PHP it doesn't work!
error:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/u381013597/> public_html/index.html on line 311
When I change 'none' to "none" there is no error but the close item doesn't work.
What is the problem?

When you print in PHP you have to watch out with strings. You define a string with single or double quotes. If your string contains for example single quotes and you defined the string with a single quote the quote in the string itself will mean end of string, so you have to escape them:
echo 'onclick="this.parentNode.style.display=\'none\';"';
As you see I used single quotes for printing here, and I escaped every single quote in the string itself with the backslash character: \
Otherwise, the string would ended before none (because there is a unescaped single quote that means the end of the string) and the parser would except a ; character that means end of command or a , character that marks that there will be other parameters, but you give none of them, it gets none instead. Thats why it throws that he get an unexpected T_STRING. If you look at your error message, you will see that it says the same as I did, just in a compact way:
error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/u381013597/> public_html/index.html on line 311
It also says that there is a Parse error: syntax error that means you mistyped something, and he also says where does the problem occurs.
Error messages are your friends, they give a hint about the problem. Read (or at least search for) them and you will be able to develop much faster.

Related

How insert an XML in a command line [duplicate]

I got one error while passing the arguments to outlook_DataParsing.sh:
$ sh outlook_DataParsing.sh delete node doc('/opt/ws40/contacts.xml')//Directory/Contacts/Contact[#id='22222']
and I am reading all the arguments as:
str=$#
The error is following:
-bash: syntax error near unexpected token `('
Can anybody help me?
There are a number of "special" characters in a shell command, including $()[]
Most of these can simply be passed by enclosing the parameter in double quotes
foo "(hello)[]"
This however will not fix the $ sign, as it is intended for variables. You can instead use single quotes to pass a $ sign
foo '$im_not_a_variable'
If all else fails, ANY character can be escaped with a backslash \ including a space (no quotes needed)
foo \(hello\)\[\]\ \$im_not_a_variable

Zend - Autoloader issue

I'm new to Zend (and here) & after getting it installed, I'm running into this
error: Parse error: syntax error, unexpected 'Zend' (T_STRING) in C:\xampp\htdocs\zend\public\invoice.php on line 4
<?php
define("ZF_PATH", realpath("C:\xampp\htdocs\zend\"));
set_include_path(get_include_path('C:\xampp\htdocs\zend\library') . PATH_SEPARATOR . ZF_PATH);
require_once "Zend\Loader\StandardAutoloader.php";
This is the initial tutorial that I was following: http://www.sitepoint.com/generating-invoices-with-zend_pdf/
I'm basically just looking for a way to generate a report or page off of a form submitted to a MySQL database.
The \ is an escape character and when in front of a " is escapes that quote so PHP thinks it is part of that string and continues to look for the closing quote. You can see in the syntax highlighting that PHP considers everything up to Zend to be part of the same string.
To fix this you can either use double slashes:
define("ZF_PATH", realpath("C:\\xampp\\htdocs\\zend\\"));
or use / instead of \
define("ZF_PATH", realpath("C:/xampp/htdocs/zend/"));

spacing between square brackets of an array

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.

Syntax Error When Trying preg_replace()

I'm trying to remove repeated slashes and while I'm tying it, I get errors. It seems some characters have to be escaped but I can't tell which one.
<?php
$path = preg_replace('(\\){2,}', '$1', 'z:\\\aaa\\\\bbb\c\ddd\');
echo $path;
?>
This gives,
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE
Could somebody fix this?
This part:
'z:\\\aaa\\\\bbb\c\ddd\'
should be:
'z:\\\aaa\\\\bbb\c\ddd\\'
You're escaping the closing quotation mark with a backslash, so the string doesn't end.

PHP lines with XML cause unexpected '>' errors

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.

Categories