php - writing special characters to txt file -


i reading data remote file, got every thing working till point when write specific lines text file.
problem here is, when write girl's goldtone 'x' cz ring becomes girl & apos;s goldtone &apos ;x & apos; cz ring in txt file.
how write txt file retains text written above , not show character code actual character.
sample of code.

$content_to_write = '<li class="category-top"><span class="top-span"><a class="category-top" href="'.$linktext.'.html">'.$productname.'</a></span></li>'."\r\n";                 fwrite($fp, $content_to_write);   $linktext = "girls-goldtone-x-cz-ring";   $productname = "girl's goldtone 'x' cz ring";   

var_dump

string '<li class="category-top"><span class="top-span"><a class="category-top" href="stellar-steed-gallery-wrapped-canvas-art.html">&apos;stellar steed&apos; gallery-wrapped canvas art</a></span></li> 

' (length=195)

code

                $productname =$linktext;                   $linktext = str_replace(" ", "-", $linktext);                 $delchar = substr($linktext, -1);                 if($delchar == '.')                 {                     $linktext = substr($linktext, 0, -1);                 }                  $linktext = removerepeated($linktext);                 $linktext = remove_invalid_char($linktext);                 $productname = html_entity_decode($productname);                 $content_to_write = '<li class="category-top"><span class="top-span"><a class="category-top" href="'.$linktext.'.html">'.$productname.'</a></span></li>'."\r\n";                 var_dump($content_to_write);                 fwrite($fp, utf8_encode($content_to_write)); 

fwrite binary-safe, meaning doesn't encoding stuff writes whatever feed directly file. looks $productname variable you're writing entity-encoded before writing. try running html_entity_decode on variable first.

note html_entity_decode doesn't touch single quotes (&apos;) default; you'll have set ent_quotes flag in second parameter. might want explicitly specify encoding in third parameter.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -