2

I ran into this problem: I wanna write an iframe tag into a text file using a PHP script. The writing script:

    <?php
    // Open the text file
    $f = fopen("text.txt", "a");
    // Write text
    fwrite($f, $_POST["textblock"] . "\n");
    // Close the text file
    fclose($f);
    // Redirect
    header("Location: http://umaster.tk/admin/index.php");
    //Error
    die();
    ?>

The reading script:

    <?php
    $myfile = fopen("szoveg.txt", "r") or die("Unable to open file!");
    while(!feof($myfile)) {
    echo fgets($myfile);
    }
    fclose($myfile);
    ?>

The iframe:

   <iframe width="560" height="315" src="https://www.youtube.com/embed/asNzJ2mFCm0" frameborder="0" allowfullscreen>
   </iframe>

And what the php script wrote:

    <iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/asNzJ2mFCm0\" frameborder=\"0\" allowfullscreen></iframe        

How can I get rid of these backslashes?

UMaster
  • 23
  • 4

1 Answers1

1

PHP has a built in function called stripslashes

http://php.net/manual/en/function.stripslashes.php

  • Thanx, im going to experiment with it – UMaster Mar 29 '15 at 12:35
  • How should i use it? Im new in Php – UMaster Mar 29 '15 at 12:37
  • 1
    `fwrite($f, stripslashes($_POST["textblock"]) . "\n");` – D4V1D Mar 29 '15 at 12:39
  • Have a look in your saved file, if the slashes are present, then you want to use it when you are saving the data, like this `fwrite($f, stripslashes($_POST["textblock"]) . "\n");` If the data is already stored without the slashes, and they are being added when you read from it, then you would use it like this: `echo stripslashes(fgets($myfile));`. The rule of thumb is that you don't store escaped data. –  Mar 29 '15 at 12:40
  • Yes it even works with PHP 4 –  Mar 29 '15 at 12:42