user6591285
user6591285

Reputation:

can't write a file properly using php

<?php
$CreateFile = fopen("allinfo.html","a") or die("unable to create file");
                        $up = "<div class="infofilediv">";
                        $fwrite($CreateFile,$up);
                        $fclose($CreateFile);
?>

When I am creating this html file I am not able to write "infofilediv" with double quotation marks. How am I able to escape these characters?

Upvotes: 1

Views: 177

Answers (2)

Just Rudy
Just Rudy

Reputation: 700

Escape the double-quotes around infofilediv and $ before function:

$CreateFile = fopen("allinfo.html","a") or die("unable to create file");
                $up = "<div class=\"infofilediv\">";
                fwrite($CreateFile,$up);
                fclose($CreateFile);

Upvotes: 1

Mo Shal
Mo Shal

Reputation: 1637

you have two problem first with double-quotes here:

$up = "<div class="infofilediv">";

you can solve it by two ways :

1) use double-quotes first time and single-quotes second vise versa like this :

$up = "<div class='infofilediv'>";

2) escape double-quotes in second time like this :

$up = "<div class=\"infofilediv\">"; 

second with $ before function

$fwrite($CreateFile,$up);
$fclose($CreateFile);

replace with

 fwrite($CreateFile,$up);
 fclose($CreateFile);

$ use with variables

$hello="hello world";

Upvotes: 2

Related Questions