Tony33 Tony33 - 1 year ago 72
PHP Question

Php fwrite not working when content has quotes

Supposing i have this kind of text passing through a form:

Hello my name is Mike, friends call me "SuperMike", hello 'All'!

As you can see , the text contains both type of quotes ( ' " ) and when i try to write a file, it just goes wrong (blank file).

$text = $_POST['text'];
$myfile = fopen("text.html", "w");
fwrite($myfile, $text);

Answer Source

As per my understanding ,below code will help you

<form method="post">
    <textarea name="valll"></textarea>
    <input type="submit" name="ff">
if(isset($_POST['ff'])) {
    $text = base64_encode($_POST['valll']);
    /*echo $_POST['valll'];
    $myfile = fopen("text.html", "w");
    fwrite($myfile, base64_decode($text));

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download