Forum: Ruby on Rails Convert =?iso-8859-1?q?=22=E9=22_in_=22=26eacute=3B=22?=

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
oo00oo (Guest)
on 2005-12-30 21:47
(Received via mailing list)
I try to find an function to convert characters in html chars. "é"
become "é"

There is something in RoR 1.0 to do that ?
Alain R. (Guest)
on 2005-12-30 23:18
(Received via mailing list)
oo00oo
     > I try to find an function to convert characters in html chars.
"é"     > become "é"


If you're a TextMate user,
    1°: select the character to convert
    2°: press Command+&
and
voilà.
Alain
Gerard (Guest)
on 2005-12-30 23:27
(Received via mailing list)
Hi,

Don't know where you live (language wise), but if you use charset
"ISO-8859-15" these are properly handeld in several browsers. Full html
metatag is as follows:

<meta http-equiv="Content-Type"
content="text/html;charset=ISO-8859-15"/>

Regards,

Gerard.

On Friday 30 December 2005 20:46, oo00oo tried to type something like:
> I try to find an function to convert characters in html chars. "é"
> become "&eacute;"
>
> There is something in RoR 1.0 to do that ?
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails

--
"Who cares if it doesn't do anything?  It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."

My $Grtz =~ Gerard;
~
:wq!
Thomas F. (Guest)
on 2005-12-31 01:58
(Received via mailing list)
If you're using UTF-8, you can try my tip for converting UTF-8
characters in to numerical
HTML entities. These take the form of &#XXXX; and describe a unicode
character code;
works the same way as named entities like &eacute; do.

See http://rails.techno-weenie.net/tip/2005/12/30/
unicode_escaping_h_variant

-Thomas


Am 30.12.2005 um 20:46 schrieb oo00oo:
oo00oo (Guest)
on 2006-01-01 16:40
(Received via mailing list)
Thanks for reply. I write this little function to do what I need.

<%= getStringEncodedToHtml ( "héhà" ) %> ( function below )
become
h&eacute;h&agrave;

I'm new to RoR and Ruby. Someone could tell me if this function could be
more optimized ?
I use has_key but perhaprs there is a faster method.

Thanks


def getStringEncodedToHtml ( pString )

    str = String.new( pString )

    map = {
        34 => "quot",        # "
        38 => "amp",        # &
        39 => "apos",        # '
        60 => "lt",            # <
        62 => "gt",            # >
        169 => "copy",        # ©
        171 => "laquo",        # «
        174 => "reg",        # ®
        187 => "raquo",        # »
        192 => "Agrave",    # À
        194 => "Acirc",        # Â
        198 => "AElig",        # Æ
        199 => "Ccedil",    # Ç
        200 => "Egrave",    # È
        201 => "Eacute",    # É
        202 => "Ecirc",        # Ê
        203 => "Euml",        # Ë
        206 => "Icirc",        # Î
        207 => "Iuml",        # Ï
        212 => "Ocirc",        # Ô
        214 => "Ouml",        # Ö
        217 => "Ugrave",    # Ù
        219 => "Ucirc",        # Û
        220 => "Uuml",        # Ü
        224 => "agrave",    # à
        225 => "aacute",    # á
        226 => "acirc",        # â
        228 => "auml",        # ä
        230 => "aelig",        # æ
        231 => "ccedil",    # ç
        232 => "egrave",    # è
        233 => "eacute",    # é
        234 => "ecirc",        # ê
        235 => "euml",        # ë
        238 => "icirc",        # î
        239 => "iuml",        # ï
        244 => "ocirc",        # ô
        246 => "ouml",        # ö
        249 => "ugrave",    # ù
        251 => "ucirc",        # û
        252 => "uuml",        # ü
    }

    lng = str.length
    while lng > 0
        if map.has_key?( str[ lng ] )
            str[ lng ] = "&" + map[ str[ lng ] ] + ";"
        end
        lng -= 1
    end

    return str
end
This topic is locked and can not be replied to.