I’m trying to append content from a file to a string.
opening the file using iso-8859-1 encoding and setting the string to same encoding.
but when trying to concatenate values I get a incompatible character encodings: UTF-8 and ISO-8859-1 (Encoding::CompatibilityError) error.
why this happen if both strings are of same encoding?
actually I have no UTF-8 strings there.
sql = "
INSERT INTO pages
(meta_title, meta_description, meta_keywords, title, URL, content)
VALUES ('%s', '%s', '%s', '%s', '%s', '%s');
".force_encoding('iso-8859-1') # setting string to iso-8859-1
Dir['./*'].select { |e| File.file? e }.each do |e|
f = File.open(e, "r:iso-8859-1") # opening the file using iso-8859-1
# extracting meta, title etc
puts sql % [*meta, title, url, content]
end
Try to use explicit encoding on extracted content as well.
Like this: