crazy time with str_replace()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello;
I really am trying to use this as a last resort but sometimes the solution refuses to present itself just by swearing and
staring and poking around with comments and print statements.
line 197: $rdata = str_replace("// \$routes[] = '';\n", "\$routes['$usr'] = '../$path/in';\n// \$routes[] = '';\n", $rdata); // this is not working line 223: $rrdata = str_replace("// \$routes[] = '';\n", "\$routes['$user_long'] = '../$r/in';\n// \$routes[] = '';\n", $rrdata); // this is working

These two lines are in a function I wrote. I add the line numbers to indicate that they are separated by some code. But they perform identical tasks on two different files with the identical names in two separate directories. As far as I can tell the target strings are identical in both of the files; initially, one file is a copy of the other, but change as array items are added. Or are supposed to. The string // $routes[] = '';\n is used as a template for adding new array items. (in the str_replace code, the $ is escaped with \ so it will be interpreted literally) The problem is the str_replace operation works on the $rrdata variable and not the $rdata variable. When testing the $rdata variable with a print statement, there is no change to the target string; I.E. // \$routes[] = '';\n is not replaced with \$routes['$usr'] = '../$path/in';\n// \$routes[] = '';\n.
The file is a php file that i am trying to write to.
There is no read errors on fopen nor fread on the file in the first line. The file that the first str_replace() is supposed to modify is in the same directory as the script that has this function. The function is included in another script file in the same directory. The second file that str_replace is working on is from a file opened in another directory. I have checked read and write permissions on both files and directories and found nothing i could point at as the cause of the failure and in fact I would expect the fopen function to fail if there was a permissions problem. It is obviously opening and reading the file successfully, as using print before the str_replace operation show that the file has been properly read into the $rdata variable. In case it is not clear, the two marks after the = sign in each line indicate an empty string surrounded by single quotes, that makes it appear
to be one double quotation mark when it is not.
Can anyone see what I am not seeing, or tell me something that I should be aware of that I may not be.
thanks for your time;
JK

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux