0

I have this string of data with some chords and their names:

$html="< img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAAA4AQMAAAB31mwxAAAABlBMVEX///8AAABVwtN+AAAAAXRSTlMAQObYZgAAAEVJREFUeF5jIApwgDCIEAFhEKEEwkoIEYQaLID/PxD8AMmDARpDBsaww8JAqMHUTsBkGRkow84Ok4FQQ5zJZDAG0GTCAADwOiM87WVzggAAAABJRU5ErkJggg==" alt="E" /> E

When I try to put this into a file

file_put_contents("data2.html",$html);

I just creates an empty file.

bfb 1985
  • 29
  • 1
  • You need to escape quotes in your assignment of the string to `$html`. `$html=" – Brad Feb 15 '13 at 22:23
  • 1
    1. You never closed the `$html` variable; 2. Escape the quotes; 3. Remove the space between `<` and `img`. – aborted Feb 15 '13 at 22:24

1 Answers1

3

Change your $html variable to this:

$html = '<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAAA4AQMAAAB31mwxAAAABlBMVEX///8AAABVwtN+AAAAAXRSTlMAQObYZgAAAEVJREFUeF5jIApwgDCIEAFhEKEEwkoIEYQaLID/PxD8AMmDARpDBsaww8JAqMHUTsBkGRkow84Ok4FQQ5zJZDAG0GTCAADwOiM87WVzggAAAABJRU5ErkJggg==" alt="E" /> E';

And then do the file_put_contents('data2.html', $html); part.

What we did here was replace the double quotes with single quotes so you wouldn't need to escape the double quotes inside the string. I also put an end with a semicolon to your string, which was missing. Always remember to end a statement when you start it.

aborted
  • 4,481
  • 14
  • 69
  • 132