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 :
but same problem, this not replace sftp by <BR />sftp
the content of logs.txt is :
>file logs.txt
give this result : logs.txt: UTF-8 Unicode text
have you idea ?
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);
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 *
>file logs.txt
give this result : logs.txt: UTF-8 Unicode text
have you idea ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Maybe this function can help?
http://php.net/manual/en/function.nl2br.php
http://php.net/manual/en/function.nl2br.php
echo preg_replace('/sftp/u', $remplace, $subject);