# Html entities problem

**URL:** <https://www.ruby-forum.com/t/html-entities-problem/52912>\
**Category:** Rails\
**Created:** [December 8, 2005, 10:23am UTC](https://www.ruby-forum.com/t/html-entities-problem/52912 "2005-12-08T10:23:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brutyn\_nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@brutyn\_nick](https://www.ruby-forum.com/u/brutyn_nick)\
**Post date:** [December 8, 2005, 10:23am UTC](https://www.ruby-forum.com/t/html-entities-problem/52912/1 "2005-12-08T10:23:49Z")

</div>

hey, i import records from an excel file, but i have problems with html  
entities.

1.if i import something like this  
ChÃ¯ Ã©Ã Ã¨ de l’ rue

in database displays  
ChÃ¯ Ã©Ã Ã¨ de l’ rue Chï¿½ ï¿½ï¿½ï¿½ de l’ rue

2.and if i edit that with “ChÃ¯ Ã©Ã Ã¨ de l’ rue” on the site, i get

in database displays  
ChÃ?Â¯ Ã?Â©Ã? Ã?Â¨ de l’ rue ChÃ¯ Ã©Ã Ã¨ de l’ rue

can anyone help me what conversion i need to do?

---

<div class="post-metadata">

**Author:** ![brutyn\_nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@brutyn\_nick](https://www.ruby-forum.com/u/brutyn_nick)\
**Post date:** [December 8, 2005, 5:22pm UTC](https://www.ruby-forum.com/t/html-entities-problem/52912/2 "2005-12-08T17:22:43Z")

</div>

brutyn\_nick wrote:

> hey, i import records from an excel file, but i have problems with html  
> entities.

Could you post your code?

Also, maybe iconv can help.  
[http://wiki.rubyonrails.com/rails/pages/iconv](http://wiki.rubyonrails.com/rails/pages/iconv)

---

<div class="post-metadata">

**Author:** ![brutyn\_nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@brutyn\_nick](https://www.ruby-forum.com/u/brutyn_nick)\
**Post date:** [December 9, 2005, 9:18am UTC](https://www.ruby-forum.com/t/html-entities-problem/52912/3 "2005-12-09T09:18:55Z")

</div>

i have changed my db tu utf8-general-ci, when i edit or create an  
employee  
throught the site and i fill in “jÃ©an”, in the database comes “jÃ©an”.

when i want to import that through csv, it is fucked up, this is the  
file:  
Firstname;Lastname;Phone;Phone Pin  
Jan;Klaas;3259778899;5555  
JÃ©an;Klaas;3259778888;5556  
;Vandevelde;3259452145;0010

Stijn;;;

i get this as output for the user(correct):  
Check There were errors on these records, there were not added to the  
database.  
Import Employees  
Row 4: , Vandevelde, , 0010

- First name can’t be blank

Row 5: , , , 0000

- First name can’t be blank
- Last name can’t be blank

Row 6: Stijn, , , 0000

- Last name can’t be blank

this is my code:  
def upload  
fileupload = @params[:file]  
@msg = “”  
errors = false  
if fileupload.original\_filename.slice(-3…-1) != “csv”  
@msg = “Please only upload .csv files.”  
else  
filename = rand(9999999999).to\_s.rjust(10,“0”) + “.csv”  
folder = “C:/temp/”  
while FileTest.file?(folder + filename)  
filename = rand(9999999999).to\_s.rjust(10,“0”) + “.csv”  
end  
File.open(folder + filename, “wb”) { |f| f.write(fileupload.read) }  
csv\_file\_path = folder + filename  
firm\_id = @session[:user].firm\_id  
#CSV READING  
@first = true #skip first row (headers)  
row\_number = 2  
CSV.open(csv\_file\_path, ‘r’) do |row|  
# use row here…  
if @first  
@first = false  
else  
error = false  
errormsg = “”  
cells = Array.new  
cells = row.to\_s.split(’;’)  
if cells != nil  
first\_name = cells[0].nil? ? ‘’ : cells[0]  
last\_name = cells[1].nil? ? ‘’ : cells[1]  
phone = cells[2].nil? ? ‘’ : cells[2]  
phone\_pin = cells[3].nil? ? ‘’ : cells[3]  
#Validate values  
phone\_pin = phone\_pin.to\_s.rjust(4,“0”)

```
		@temp= Employee.new
		#SETING THE VALUES TO THE OBJECT
		@temp.first_name = first_name
		@temp.last_name = last_name
		@temp.phone = "+" + phone.to_s
		@temp.phone_pin = phone_pin
		#SAVING THE OBJECT
		if @temp.save
		else
		        errors = true
		        err = parse_errors(@temp)
		        @msg += "Row " + row_number.to_s + ": "
                            + first_name + ", " + last_name + ", " +
			phone + ", " + phone_pin + "<br/>" +
			err + "<br/>"
		end
	end
	row_number += 1
end

```

end  
if errors  
flash[:notice] = “There were errors on these records, there were not  
added to  
the database.”  
else  
flash[:notice] = “All records succesfully added to the database.”  
end  
end

* * *

Jan;Klaas;3259778899;5555  
JÃ©an;Klaas;3259778888;5556

this should be in the db but i get:  
Jan;Klaas;;5555  
J;Klaas;;5556

can anyone help me?

thanks
