Re: Command line cannot fwrite, browser can [message #174631 is a reply to message #174629] |
Thu, 23 June 2011 07:55 |
Thomas 'PointedEars'
Messages: 701 Registered: October 2010
Karma:
|
Senior Member |
|
|
Adrienne Boswell wrote:
> Thomas 'PointedEars' Lahn wrote:
>> Adrienne Boswell wrote:
>>> Jerry Stuckle writing:
>>>> Adrienne Boswell wrote:
>>>> > Thomas 'PointedEars' Lahn writing:
>>>> >>> $groupmail = fopen( $filename,'w' ) or die( 'cannot open
>>>> >>> groupmail.html' );
>>>> >> <http://www.phpfreaks.com/blog/or-die-must-die>
>>>> > Thank you for all your help, and the link. I have read it and will
>>>> > implement it.
>>>> I think you have another problem. Single vs. double quotes would
>>>> not make any difference in the code you posted.
>>> […]
>>> Yes, this is nagging me, too. I just checked it ran it right now (I
>>> also moved the script so it is not accessible to the WWW),
>>
>> This is not the World Wide Web, an application of the Internet, but
>> Usenet, a part of the Network News network (a growing part of which is
>> part of the Internet). So you may – SHOULD – as well post the
>> *relevant* *parts* of your working code here.
>
> Ok, here is the relavent piece of code (the relavent parts were snipped by
> Jerry).
ACK, thanks.
> Originally (with line numbers and I have replaced the real domain with
> example.com):
>
> 68 $filename = "C:\Inetpub\vhosts\example.com\httpdocs\groupmail
> \groupmail.html";
>
> 80 $groupmail = fopen( $filename,'w' ) or die( 'cannot open
> groupmail.html' );
>
>
> Warning:
> fopen(C:\Inetpub?hosts\example.com\httpdocs\groupmail\groupmail.ht ml):
> failed to open stream: Invalid argument in C:\Inetpub\vhosts
> \example.com\httpdocs\groupmail.php on line 80 cannot open groupmail.html
>
>
> So when I changed line 68 to:
>
> 68 $filename = 'C:\Inetpub\vhosts\example.com\httpdocs\groupmail
> \groupmail.html';
I can see the problem now. You have used the sequence "\v" in your string
literal. That makes the difference, because in double-quoted strings it is
parsed as a <VT> (vertical tab) character (that originates from early TTYs
and is hardly used nowadays, but kept for backwards compatibility [1]).
Hence the question mark in the warning after the "b" of "Inetpub", and the
missing "v" after it. <VT> is not one of the printable characters, so a
replacement character is used to display it.
In a single-quoted string, that and most other escape sequences carry no
special meaning [2]. So the path fits, and the file can be opened, then.
Since you cannot know beforehand which escape sequences are considered by a
certain version of PHP (other than `\\'), you should always escape literal
backslashes in string literals: "\\" or '\\' [2]. In fact, you MUST escape
them when at the end of the string value, because otherwise \" or \'
constitute escape sequences of themself, and the string value is not
terminated:
$ php -a
Interactive mode enabled
<?php echo "foo\";
^D
PHP Parse error: syntax error, unexpected $end, expecting T_VARIABLE or
T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN in - on line 2
$ php -a
Interactive mode enabled
<?php echo 'foo\';
^D
PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE in - on
line 1
$ php -v
PHP 5.3.3-7+squeeze1 with Suhosin-Patch (cli) (built: Mar 18 2011 17:22:52)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with XCache v1.3.1, Copyright (c) 2005-2010, by mOo
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH
[FYI: ^D stands for the keyboard shortcut Ctrl+D, which prints <ETX> (end of
text), an ASCII character (code point 0x03) that signals to the process that
the standard input stream is finished. It can also be used to `logout'
quickly from a unixoid shell.]
But for file paths you can replace the backslashes with forward slashes
(`/') even in WinDOS, which do not need to be escaped [3].
>> That puts into serious doubt whether you are worth getting further,
>> rather time-consuming, answers like the ones I give to you. Think
>> about that.
>
> One of the reasons I came here was because I have high respect for your
> knowledge.
Thank you.
> You might think that because I'm girl I have thin skin, but I don't.
All people are the same before PointedEars ;-)
> I have been around Usenet since 1996, so I have seen a lot,
> including your latest run-in with Jukka Korpela.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
What is that supposed to mean? (You may reply to this by PM.)
Please trim your quotes to the relevant minimum [4].
PointedEars
___________
[1] <http://en.wikipedia.org/wiki/Vertical_tab#Tab_characters>
[2] <http://php.net/manual/en/language.types.string.php>
[3] <http://php.net/fopen>
[4] <http://www.netmeister.org/news/learn2quote.html>
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(at)news(dot)demon(dot)co(dot)uk> (2004)
|
|
|