Link to home
Start Free TrialLog in
Avatar of billy_howard
billy_howard

asked on

HTML Pound Symblol incorrectly showing.

Hi Experts,

I am having troulbe with a project that I have just taken over.

The previous person who developed the website was rather lazy it would seem, and is not performing a HTML charicter conversion on input or output to/from the database.

This means that things like the £ pound sign show up badly and show up as "£" rather than just "£".

Now I know that I really do need to sort this out propperly, but the customer dosen't have the budget to allow me to go in and manually change each input or output to have a HTML char conversion on it.

Is there something that I can quickly do that will sort this out? For example is there some kind of javascript that I can implement that will change £ to £? Granted I could just do an update on the database and convert £ into £ but this method is horrible as things are updated often and would lead to bigger problems down the line.

Or is there perhaps some kind of HTML that I can use, to force the browser to parse the £ symbols propperly?

My current HTML header is included in code below, and to my knowledge that should allow me to temporarily view pound signs as £ rather than £.

Can you think of/suggest anything I can do?



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Open in new window

Avatar of Sammaye
Sammaye

This is only drafted off of the top of my head. Is that what you are trying to do?
function replace(String){ 
var newString  = String.replace("£","&pound"); 
return newString; 
}

Open in new window

Since what you say is that you want £ to convert as &pound but then you say you want to view pound sign correctly via changing the header...in php pound symbols should read in perfectly fine into a database so long as you escape the data before hand...then use stripSlashes($string); to remove the escaped slashes from text
This reference may be helpful:
http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

Do you need UTF-8 to display your pages?  What if you use the browser default instead?

If you decide to translate the character to the entity, be sure to use &pound; in the PHP scripts.  Try running just what is posted here and let us know how it comes out.  Thanks, ~Ray
<?php
echo "<br/>THE HTML ENTITY IS &pound; AND THE EXPLICIT CHARACTER IS £";

Open in new window

Avatar of billy_howard

ASKER

Sorry boys, thanks for the responces I don't think I made my position clear.

Basically the customer has no budget for me to edit each PHP file (with this bloke's horrible code) and change the output to escape the pound sign.

I don't want to change it in the database itself, because if I convert it to &pound; hard coded, that dosen't solve the problem for me, because when they add a new item to the database with the £ sign, it won't convert it to the &pound; and I would have to run another update to get it to show correctly.

Again I could modify the input files, but again we are talking about dosens of badly coded non standards compliant files, which again the customer dosen't have the budget for at the moment.

Now I am looking for a serious hack about method that will work for the moment and allow it to show propperly.

I was wondering if there was a way in JS to search through the html doc, and do a replacement for the user, from the £ to &pound;?

Cheers

Tom
ASKER CERTIFIED SOLUTION
Avatar of Sammaye
Sammaye

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I can't guarantee this ones function and it most likely is wrong but this is what I drafted up as a third choice if you knew the elements the pound symbol would be printed in:

 $( "#div a.pound" ).each(
 
    function( intIndex ){
       var String = this.html();
       var newString  = String.replace("£","&pound"); 
       this.html(newString);
     }
       
  );

Open in new window

Just to clarify my last post with example etc. Apparently something like this could work for elements you know would contain pound signs. I am using JQuery for this function by the way:



 $(document).ready(function() {
      $("#records").find("span").each(function(i) {
           var String = $(this).html();
           var newString  = String.replace("£","&pound"); 
           $(this).html(newString);
       });
 
 });

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ray,

Thanks for the responce and the code snippet will try that tomorrow.

I am very gradually beginning to hate this customer with a passion. Took on the project with the idea of not huge ammounts of work involved. Getting to a stage now where I just want to tell them to royally shove it..

But I digress.

I will try your snip tomorrow morning and get back to you asap.

Cheers
Good luck with it! ~Ray
lewedhdfhf
rgr