utf-8

tFPDF generates an empty pdf file

浪子不回头ぞ 提交于 2020-05-29 13:04:48
问题 I am trying to generate a PDF file in PHP using the tFPDF library. I started with FPDF and it worked fine except that the UTF-8 characters were garbled. After some searching, I found that one could implement tFPDF to include UTF-8 characters in a PDF file. But all my attempts have resulted in an empty file that cannot be opened--0 KB file written to my hard drive and "There's a problem with the file format" message when I double click it. Here is my code. I'm getting no PHP errors in the

tFPDF generates an empty pdf file

安稳与你 提交于 2020-05-29 13:01:51
问题 I am trying to generate a PDF file in PHP using the tFPDF library. I started with FPDF and it worked fine except that the UTF-8 characters were garbled. After some searching, I found that one could implement tFPDF to include UTF-8 characters in a PDF file. But all my attempts have resulted in an empty file that cannot be opened--0 KB file written to my hard drive and "There's a problem with the file format" message when I double click it. Here is my code. I'm getting no PHP errors in the

PHP DomDocument - why is en dash “–” converted to –

元气小坏坏 提交于 2020-05-28 05:32:25
问题 I am using DOMDocument to extract some paragraphs. Here is how my initial htm file that I am impotrting looks like: <html> <head> <title>Toxins</title> </head> <body> <p class=8reference><span>1.</span><span>Sivonen, K.; Jones, G. Cyanobacterial Toxins. In <i>Toxic Cyanobacteria in Water. A Guide to Their Public Health Consequences, Monitoring and Management</i>; Chorus, I., Bartram, J., Eds.; E. and F.N. Spon: London, UK, 1999; pp. 41–111.</span></p> </body> </html> When I am doing: $dom

Laravel: Encode JSON responses in UTF-8

最后都变了- 提交于 2020-05-27 05:15:32
问题 I want to encode the JSON responses of my API to UTF-8, but every time I make a response I don't want to do this: return response()->json($res,200,['Content-type'=>'application/json;charset=utf-8'],JSON_UNESCAPED_UNICODE); So I thought about making a middleware for all API routes which handle(...) function would be this: public function handle($request, Closure $next) { $response = $next($request); $response->header('Content-type','application/json; charset=utf-8'); return $next($request); }

How to convert utf8 string to utf8 byte array?

﹥>﹥吖頭↗ 提交于 2020-05-25 05:48:06
问题 How can I convert string to utf8 byte array, I have this sample code: This works ok: StreamWriter file = new StreamWriter(file1, false, Encoding.UTF8); file.WriteLine(utf8string); file.Close(); This works wrong, file is in ASCII: byte[] bytes = System.Text.UTF8Encoding.UTF8.GetBytes(utf8string); FileStream fs = new FileStream(file2, FileMode.CreateNew); fs.Write(bytes, 0, bytes.Length); fs.Close(); I would like to get byte array what returned by this function: System.IO.File.ReadAllBytes(path

'utf-8' codec can't decode byte 0xe2 : invalid continuation byte error

谁说胖子不能爱 提交于 2020-05-24 03:41:06
问题 I am trying to read all PDF files from a folder to look for a number using regular expression. On inspection, the charset for PDFs is 'UTF-8'. Throws this error: 'utf-8' codec can't decode byte 0xe2 in position 10: invalid continuation byte Tried reading in binary mode, tried Latin-1 encoding, but it shows all special characters so nothing shows up in search. import os import re import pandas as pd download_file_path = "C:\\Users\\...\\..\\" for file_name in os.listdir(download_file_path):

'utf-8' codec can't decode byte 0xe2 : invalid continuation byte error

柔情痞子 提交于 2020-05-24 03:40:01
问题 I am trying to read all PDF files from a folder to look for a number using regular expression. On inspection, the charset for PDFs is 'UTF-8'. Throws this error: 'utf-8' codec can't decode byte 0xe2 in position 10: invalid continuation byte Tried reading in binary mode, tried Latin-1 encoding, but it shows all special characters so nothing shows up in search. import os import re import pandas as pd download_file_path = "C:\\Users\\...\\..\\" for file_name in os.listdir(download_file_path):

mod_cgi + utf8 + Python3 produces no output

拈花ヽ惹草 提交于 2020-05-23 10:55:06
问题 If you create this app.py #!/usr/bin/python3 print("Content-Type: text/plain;charset=utf-8\n") print("Hello World!") and you enable CGI in .htaccess with: Options +ExecCGI AddHandler cgi-script .py it totally works: http://example.com/app.py displays "Hello world!". However if you add an accented character: print("Quel été!") this does not work anymore: the output page is empty in the browser. Question: how to output a UTF8 content with Python3 + mod_cgi ? NB: the .py file is saved with UTF8

pandas to_csv: ascii can't encode character

时光总嘲笑我的痴心妄想 提交于 2020-05-23 02:51:07
问题 I'm trying to read and write a dataframe to a pipe-delimited file. Some of the characters are non-Roman letters (`, ç, ñ, etc.). But it breaks when I try to write out the accents as ASCII. df = pd.read_csv('filename.txt',sep='|', encoding='utf-8') <do stuff> newdf.to_csv('output.txt', sep='|', index=False, encoding='ascii') ------- File "<ipython-input-63-ae528ab37b8f>", line 21, in <module> newdf.to_csv(filename,sep='|',index=False, encoding='ascii') File "C:\Users\aliceell\AppData\Local

problems reading correctly a csv due to UnicodeDecodeError in Python3

不问归期 提交于 2020-05-17 14:47:07
问题 I create a csv file in wich I put some lyrics of songs, using this: with io.open('songs.csv', 'a+',encoding='utf-8') as file: writer = csv.writer(file , dialect='excel') writer.writerow(input_row) the csv ( opened with excel) is quite strange - I don't know how to upload files here so please sorry for the pic. - As you can see, the delimiters for the csv are commas, (the columns should be Artist, Album, Title, Lyric ) I noticed that I had some spanish and italian lyrics, and characters like