开发者

control characters in php file handling

开发者 https://www.devze.com 2023-03-26 17:27 出处:网络
I\'m trying to write the £ symbol to a file using PHP. However when I open the file I have created the £ sign is always preceded with the symbol ¬ (on my keyboard this is an alt L开发者_如何学Pytho

I'm trying to write the £ symbol to a file using PHP. However when I open the file I have created the £ sign is always preceded with the symbol ¬ (on my keyboard this is an alt L开发者_如何学Python)

Is there anyway to suppress this?

$file=fopen($lastid,'w');
echo $file;
fwrite($file, "

    Date: $receipt_date
    Customer: $customer
    Receipt number: $id
    Description: $description


    Amount: £$NET
    VAT: £$VAT
    Total: £$gross

    test:£500

    Payment received with thanks by $payment


    UNIQUECAPTURE VAT:");
fclose($file);


That means the source code file is saved using a different encoding than the program you're opening it with is trying to interpret it with. Most likely your source code is saved as UTF-8 (and therefore the text written to the file is UTF-8) and the program is trying to read it as ISO-8859-1. £ in UTF-8 is 0xC2 0xA3, in ISO-8859-1 ¬ is 0xC2 and £ is 0xA3. Make sure the program you're trying to open it with is intelligent enough to recognize UTF-8 when it sees it or explicitly tell it to interpret the file using UTF-8.

Shameless self-promotion, because it's about exactly this topic: What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text


hi guys with a little help from my grandfather i found a way around it simply by adding

    $input = str_replace("£", "£", $input); 

the pound symbol is now shown as £
heres the final code

$input = str_replace("£", "£", $input);     
$file=fopen($lastid. $dash. $customer,'w');     

Many thanks for all your help

for some reason the second £ symbol is meant to be an &pound

0

精彩评论

暂无评论...
验证码 换一张
取 消