fwrite doesn't like spaces

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
Jonesin1974
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Nov 10, 2018 1:33 am

Sat Nov 10, 2018 1:55 am

Hi,

I'm using fwrite to create a config file but when the value has a space, it inserts a funny character.

on my form, $_POST['7ZipInstall'] has the value '7ZipInstall=C:\Program Files\7-Zip'

When I use this:

Code: Select all

fwrite($file, '7ZipInstall='. $_POST['7ZipInstall']. "\r\n");
It writes the value:

C:\Program Files\7-Zip

If I use this:

Code: Select all

fwrite($file, '7ZipInstall=C:\Program Files\7-Zip'. "\r\n");
It works as I'd expect.

Any ideas? something dodgy happening in the $_POST but not sure what.

Cheers,
J

Jonesin1974
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Nov 10, 2018 1:33 am

Sun Nov 11, 2018 4:33 am

FOund a solution :)

Code: Select all

$str = preg_replace('/[\s\pZ]+/u', ' ', $_POST['ReportHistory']);
fwrite($file, 'ReportHistory='. $str. "\r\n");

Post Reply