Jump to content

Unwanted HTML Codes in text file.


miltonos

Recommended Posts

I am attempting to write data out to a text file from a MySql database. The data in the db field is clean with no html codes (I can verify this). When I retrieve the data and then write it out to a text file in a directory under 'Apache/htdocs' all my single and double quotes have been converted to HTML Codes.

 

Here is the code I am using to write to the directory:

 

    $bs = fopen(".//downloads//" .$fileName, "w");

    fwrite($bs, $licenseFile, strlen($licenseFile));

    fclose($bs); 

 

I have even used str_replace() immediately before the fopen() call to search the $licenseFile for HTML codes and replace them with the proper characters but to no avail. Because this is a license file I cannot have errant characters reproduced in it. 

 

Thank you for any insight into what I am doing wrong.

 

Milton S.

 

Link to comment
Share on other sites

maybe try html_entity_decode() before writing to the file?

 

simcoweb,

 

Thank you for the reply. htm_entity_decode() did work. I used it as:

 

    $bs = fopen(".//downloads//" .$fileName, "w");

    fwrite($bs, html_entity_decode($licenseFile,ENT_QUOTES), strlen($licenseFile));

    fclose($bs);   

 

 

I would really like to know how the html codes are getting into my string? Is there a php.ini setting that should be configured differently?

 

Again thank you for the response.

 

Milton S.

Link to comment
Share on other sites

Sorry,

 

I got the names backwards. Thanks to genericnumber1 for a solution, and to simcoweb, yes somewhere after I get the string out of the database the single and double quotes are being converted to html codes.

 

Milton S.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.