Sajidur Rahman Sajidur Rahman - 2 months ago 8
HTML Question

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 creating this html file I can't write "infofilediv" this class. How can I solve this?

sorry for my bad english

Answer

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";