Using firebase php, I am getting following error in a simple $firebase->set($data,$location) function.
Uncaught exception 'Kreait\Firebase\Exception\FirebaseException' with
message 'The location key "rural foothills m.d." contains on of the
following invalid characters: .$#[]'
Is there a way to sanitize the value to avoid the error?
Thanks!
Sometimes you will see an error that says "Invalid data; couldn't parse JSON object, array, or value. Perhaps you're using invalid characters in your key names."
This error occurs when the fields you are trying to send to Firebase contain invalid characters. Firebase prohibits key names from containing:
. (period)
$ (dollar sign)
[ (left square bracket)
] (right square bracket)
# (hash or pound sign)
/ (forward slash)
To get around the error, you will need to manually assign names to the keys.
Reference: Common Problems with Firebase
Related
I have a url like this:
https://example.com/path/to/folder?param[key][=]=value&foo=bar
In the param definition the second key is an operator, which could be gt, lt, =, etc. The problem appears only when the operator is =.
In Laravel/Lumen I cannot parse the query part of the url because somewhere lost the left square bracket. I have tried urlencode() instead of $request->query() (which gives worst), but the result is the same.
Do you have any idea to get and parse correctly the square brackets definition?
Finally I found a suitable solution. Laravel's $request->getRequestUri() method gives the full url in the right unencoded format.
I currently knows how Zend parse operators by reading the Zend/zend_language_parser.y file of php-src. But I'm very confusing about how variables are recognized.
The Bison token is:
%token <ast> T_VARIABLE "variable (T_VARIABLE)"
How does it match the dollar prefix?
The token declaration tells us that there's a token type named T_VARIABLE that is associated with values of type ast and should be referred to as "variable (T_VARIABLE)" in error messages. It tells us nothing about which characters a T_VARIABLE token may consist of - nothing in the Bison file will tell us that.
That's because a Bison parser does not interact with characters - it interacts with tokens produced by the lexer/scanner. The parser simply consumes the tokens generated by the scanner. It does not need to know which character sequence are translated to which tokens - that's the scanner's job.
So if you want to see the dollar sign, you need to look into the scanner (zend_language_scanner.l) where you'll find (among others) this:
<ST_IN_SCRIPTING,ST_DOUBLE_QUOTES,ST_HEREDOC,ST_BACKQUOTE,ST_VAR_OFFSET>"$"{LABEL} {
RETURN_TOKEN_WITH_STR(T_VARIABLE, 1);
}
This tells us that inside regular PHP sections, double quotes, heredocs, back quotes and brackets (i.e. basically anywhere except outside of the <?php tags), a dollar followed by a label (which is defined as an arbitrary non-empty sequence of letters, numbers and underscores that doesn't start with a number) produces a T_VARIABLE token.
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.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
w3c markup validator ampersand (&) error
I am pulling records from a database to display but when I echo it W3C validator complains that there is & in the record.
I displays fine on the page. Is there something I can do to clean the string?
Presumably the error you are seeing is followed by this explanation:
An entity reference was found in the document, but there is no reference by that name defined. Often this is caused by misspelling the reference name, unencoded ampersands, or by leaving off the trailing semicolon (;). The most common cause of this error is unencoded ampersands in URLs as described by the WDG in "Ampersands in URLs".
Entity references start with an ampersand (&) and end with a semicolon (;). If you want to use a literal ampersand in your document you must encode it as "&" (even inside URLs!). Be careful to end entity references with a semicolon or your entity reference may get interpreted in connection with the following text. Also keep in mind that named entity references are case-sensitive; &Aelig; and æ are different characters.
Pay attention to that explanation and replace & (meaning "Start a character reference") with & (meaning "An ampersand character").
PHP has a function for converting all characters with special meaning in HTML into character references that you should use whenever you have some plain text that you want to put into an HTML document. Use it: htmlspecialchars() first.
I am sending a sting as a parameter to a JavaScript function:
theJSFunction('say hi dude');
Chrome gives me SyntaxError: Unexpected token ILLEGAL so after research, I've found that the following whitespaces generates the error \u2028 and \u2029.
The problem is, the string posted to the function is printed via PHP and I need it to be printed via PHP (could use ajax, but I am required to let the PHP print it).
Is there any way to remove those to characters through PHP or JavaScript?
You can replace with .replace. Passing a regular expressions with the g flag replaces all occurences, and you can include \uxxxx characters as well:
"\u2028\u2029".replace(/\u2028|\u2029/g, "").length; // 0