1

I'm using PHP to create this config file to make an executable and it works fine when the file name doesn't have any spaces but when a file have spaces it doesn't work.

the file name is inside the $readyFile variable.

What can i do to fix this ?

$content = ";!@Install@!UTF-8!
Title=\"Auto-Extract\"
ExecuteFile=\"Runner.exe\"
ExecuteParameters=\"--exe 2999.exe --file $readyFile\"
;!@InstallEnd@!";
$fp = fopen("config.txt","wb");
fwrite($fp,$content);
fclose($fp);

Thanks

Exoon
  • 1,403
  • 3
  • 18
  • 34
  • Looks like you need to double-escape a set of quotes around it; `\\\"` – Dave Apr 08 '14 at 19:05
  • Mind showing an example? \\\".$readyFile.\\\" Like that ? – Exoon Apr 08 '14 at 19:07
  • If you're trying to strip the white space in the `$readyFile` variable, this may help: [To strip whitespaces inside a variable in PHP](http://stackoverflow.com/a/1279798/2774955) – 13ruce1337 Apr 08 '14 at 19:08
  • @Exoon; yeah, but without the dots (you're using in-string substitution; no need to concat) – Dave Apr 08 '14 at 19:09
  • @Dave, Worked a treat. Want to add it as an answers so i can accept it ? – Exoon Apr 08 '14 at 19:15

2 Answers2

0

You can strip using this regex.

$content=preg_replace('/\s+/', '', $content);
Santosh Achari
  • 2,874
  • 6
  • 27
  • 50
0

You can use double-escaped quotes (\\\"):

$content = ";!@Install@!UTF-8!
Title=\"Auto-Extract\"
ExecuteFile=\"Runner.exe\"
ExecuteParameters=\"--exe 2999.exe --file \\\"$readyFile\\\"\"
;!@InstallEnd@!";

When PHP parses the string, it becomes ="--exe 2999.exe --file \"your file here\"", so your inner quotes are still escaped for the call-within-a-call.

Dave
  • 40,524
  • 11
  • 56
  • 100