Avatar of thierry91
 asked on

preg_replace not work when string is file generated by shell script


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 ?
PHPShell ScriptingLinux

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon

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);
James Williams

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Ray Paseur

Maybe this function can help?
Your help has saved me hundreds of hours of internet surfing.