This might be such a stupid simple question, so forgive me--I did search the forum and elsewhere and couldn''t find the answer... I have an HTML text string that formats nicely on a web page: s = "Mom & Dad" => "Mom & Dad" How do I convert s to just ascii characters, ie. "Mom & Dad"? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yachtman, Check out http://www.ruby-doc.org/core-1.9/classes/CGI.html#M000527 (It worked with 2.2 also)>> ugly = CGI::escapeHTML(''<BR><A HREF="url"></A>'')=> "<BR><A HREF="url"></A>">> print CGI::unescapeElement(ugly, "A", "IMG")<BR><A HREF="url"></A>=> nil>> print CGI::unescapeElement(ugly, "A", "IMG", "BR")<BR><A HREF="url"></A>=> nil There might be a higher level function too, but this shows you how you might use this directly Al On Feb 9, 7:34 pm, yachtman <carson.c...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This might be such a stupid simple question, so forgive me--I did > search the forum and elsewhere and couldn''t find the answer... > > I have an HTML text string that formats nicely on a web page: > > s = "Mom & Dad" => "Mom & Dad" > > How do I convert s to just ascii characters, ie. "Mom & Dad"?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
yachtman wrote:> This might be such a stupid simple question, so forgive me--I did > search the forum and elsewhere and couldn''t find the answer... > > I have an HTML text string that formats nicely on a web page: > > s = "Mom & Dad" => "Mom & Dad" > > How do I convert s to just ascii characters, ie. "Mom & Dad"?I haven''t tried this, but it looks like a robust solution that might work for you: http://htmlentities.rubyforge.org/ -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Of course, you can''t use this to handle all possible encoded strings On Mon, Feb 9, 2009 at 8:29 PM, stretch <stretch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Yachtman, > > Check out http://www.ruby-doc.org/core-1.9/classes/CGI.html#M000527 > (It worked with 2.2 also) > > >> ugly = CGI::escapeHTML(''<BR><A HREF="url"></A>'') > => "<BR><A HREF="url"></A>" > > >> print CGI::unescapeElement(ugly, "A", "IMG") > <BR><A HREF="url"></A>=> nil > > >> print CGI::unescapeElement(ugly, "A", "IMG", "BR") > <BR><A HREF="url"></A>=> nil > > There might be a higher level function too, but this shows you how you > might use this directly > > Al > > On Feb 9, 7:34 pm, yachtman <carson.c...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > This might be such a stupid simple question, so forgive me--I did > > search the forum and elsewhere and couldn''t find the answer... > > > > I have an HTML text string that formats nicely on a web page: > > > > s = "Mom & Dad" => "Mom & Dad" > > > > How do I convert s to just ascii characters, ie. "Mom & Dad"? > > >-- Available for Ruby on Rails development opportunities --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---