php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39983 writing a backslash int a variable doesn't appear
Submitted: 2006-12-29 08:11 UTC Modified: 2007-01-09 13:31 UTC
From: mail at siegfried-bauer dot de Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.2.0 OS: Linux, kernel 2.6.16.13-4
Private report: No CVE-ID: None
 [2006-12-29 08:11 UTC] mail at siegfried-bauer dot de
Description:
------------
can't write a backslash into a variable.

Reproduce code:
---------------
#!/home/bauer/prog/php-5.1.6/sapi/cli/php

<?

$fp=fopen("out", "w");
printf("Hello World!\n with \\ one \\\n");
$s=sprintf("Hello World!\n with \\ one \\\n");
fwrite($fp, $s);
fclose($fp);

$fp=fopen("out2", "w");
fprintf($fp, "Hello World!\n with \\ one \\\n");
fclose($fp);

?>


Expected result:
----------------
out doesn't contain any backslas.
out2 yet.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-29 10:55 UTC] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 [2006-12-29 14:58 UTC] mail at siegfried-bauer dot de
my old configuration:
 apache_1.3.31
 php-4.3.3
 kernel 2.4.21
worked different!
 [2006-12-29 15:05 UTC] mail at siegfried-bauer dot de
try perl an d you receive what you will expect!

#!/usr/bin/perl

printf("This is a \\\n");
my $a=sprintf("\\");
printf("var \$a contains %s\n",$a);
 [2007-01-09 13:31 UTC] mail at siegfried-bauer dot de
the problem is:
fread calls addslashes after reading the file.
fwrite calls stripslashes before writing the file.
fprintf neither doesn't call stripslashes nor addslashes.

so, when using fwrite you have to escape a \ four times.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC