Link to home
Start Free TrialLog in
Avatar of thierry91
thierry91

asked on

preg_replace not work when string is file generated by shell script

hello

I generates log file for bash script :
sh toto.sh>>logs.txt

I want to replace the line break or newline by <BR />
but this not have worked

I have tested to replace sftp by <BR />sftp
with :
$file = 'logs.txt';
$subject = readfile($file);
$remplace = '<BR />sftp';
echo preg_replace('/sftp/u', $remplace, $subject);

Open in new window


but same problem, this not replace sftp by <BR />sftp

the content of logs.txt is :
sftp> cd /products/
sftp> lcd ..
sftp> lcd /data/www/composants/products
sftp> put *

Open in new window


>file logs.txt
give this result : logs.txt: UTF-8 Unicode text


have you idea ?
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

This line seems to perform the replacement and displays the output, but I don't see anything that would actually write to the logs.txt and change the file data:

  echo preg_replace('/sftp/u', $remplace, $subject);
ASKER CERTIFIED SOLUTION
Avatar of James Williams
James Williams
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial