Write to html to a file (problems with / in front of ")

Discussion in 'PHP' started by azarat, Aug 17, 2010.

  1. #1
    Hi there,

    I'm trying to write a html file via php, the html file just contains standard html.

    I'm doing this with fopen / fwrite / fclose.

    		$fh = fopen($file, 'w') or die("can't open file");
    		$stringData = "$html";
    		fwrite($fh, $stringData);
    		fclose($fh);
    PHP:
    However when I open the html file it have a \ in front of all the " which causes a problem. Fx:

    <td width=\"25px\">
    HTML:
    And what I want it to be:

    <td width="25px">
    HTML:
    Anyone know how I can fix this problem?

    Thanks :)
     
    azarat, Aug 17, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    I'm assumming you get the $html from a form? - theirs a possibility the slashes are caused by magic_quotes.

    Theirfore change:

    fwrite($fh, $stringData);
    PHP:
    to:

    fwrite($fh, stripslashes($stringData));
    PHP:
     
    danx10, Aug 17, 2010 IP
  3. azarat

    azarat Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ah of course, actually thought I had it disabled. Thanks mate :)
    Anyway wrote this if anyone is interested should work with any configuration:

    
    		$fh = fopen($file, 'w') or die("can't open file");
    		$magic_quotes_active = get_magic_quotes_gpc();
    		if ($magic_quotes_active){
    			$stringData = stripslashes($html);
    		}
    		else {
    			$stringData = $html;
    		}
    		fwrite($fh, $stringData);
    		fclose($fh);
    
    PHP:
     
    azarat, Aug 17, 2010 IP