Zend - Autoloader issue - php

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/"));

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

preg_replace not working as expected replacing backslashes?

I was using the delimiters described in this answer:
Here is shell php I'm using to demonstrate the problem:
I'm using a function on a web project that replaces a namespace syntax for a path, eg:
\org\project\namespace\access
should be converted to:
/org/project/namespace/access
But I tried many ways, some threw the following warning:
Warning: preg_replace(): No ending delimiter '/' found in...
Which I don't want to show.
The warning above shows when using this as regex: /\\/
extra: (please look at the image) why it shows a bad encoded string?
UPDATE: why does it not work as this PHP Live Regex ?
You need to use "/\\\\/" instead of "/\\/" because \\ will produce \ (a single backslash) in a PHP string literal.
See http://php.net/manual/en/language.types.string.php
Why are you using regular expressions for such simple case? Stick to str_replace() or strtr():
echo strtr($str, ['\\' => '/']);

PHP Line Feeds "\n" Not Saving

For some reason with my code which I'm using \n to break the line, isn't working.
It is outputting without breaking the lines.
$file = "availables.txt";
$current .= $test."\n";
file_put_contents($file, $current);
I'm not sure what's wrong but I read that using single quotes (') doesn't work and I have to use double quotes (") which is what I'm using.
I couldn't really find much but I'm sure this is just a simple issue :)
As alluded to in the comments the issue is in selecting the correct line ending symbol for the platform.
The core constant PHP_EOL will do this for you allowing you to create portable code.
The correct 'End Of Line' symbol for this platform. Available since PHP 4.3.10 and PHP 5.0.2
It's true that a line feed character enclosed in single quotes won't work, that's simply because PHP will insert a backspace \ followed by an n into the file. This results in the ASCII/UTF-8 hex code 0x2F0x6E instead of simply 0xA.
Using either "\n" or the predefined constant PHP_EOL which will always contain the correct line feed combination for your platform will resolve this issue.
There's absolutely nothing wrong with the code you posted in your question. So what's wrong? My guess is the program you use to view the resulting file. Some broken Windows applications won't read the line feed correctly because they expect the file to use Windows line feeds (which is a combination of line feed and carriage return as you might know).
You're using PHP, output the file in your browser (no matter which), they'll handle it correctly. Simply:
<?php
header("content-type: text/plain");
echo "hello\nworld";
And you'll see that everything is fine.
You can write you variable inside double quotes like this
$current .= "$test\n";

making close button with java script in 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.

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