Daniish
asked on
HTML special characters not being caught - please can someone explain why?
Hello,
I have been using the function, parseToXML, in the attached code snippet to catch html special characters on my site for quite a while now and it has been working well.
Today i added several new fields to a table in my database and even though i am applying the same function to those new fields, it seems it is no longer able to replace the '&' and this is preventing my site from running.
Please can someone explain why this is happening and or suggest how i might fix it ?
Many thanks
p.s. contrast my current site (www.globexposure.net/index.php) and my current xml data script (www.globexposure.net/includes/read.php) >>>>
with my old site (www.globexposure.net/index_old.php)--- where i am not reading the data from the new fields (www.globexposure.net/includes/read_old.php)
read.php.txt
I have been using the function, parseToXML, in the attached code snippet to catch html special characters on my site for quite a while now and it has been working well.
Today i added several new fields to a table in my database and even though i am applying the same function to those new fields, it seems it is no longer able to replace the '&' and this is preventing my site from running.
Please can someone explain why this is happening and or suggest how i might fix it ?
Many thanks
p.s. contrast my current site (www.globexposure.net/index.php) and my current xml data script (www.globexposure.net/includes/read.php) >>>>
with my old site (www.globexposure.net/index_old.php)--- where i am not reading the data from the new fields (www.globexposure.net/includes/read_old.php)
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
$xmlStr=str_replace('£','£',$xmlStr);
$xmlStr=str_replace(chr(0x20).chr(0x10), '‐', $xmlStr);
// the line above should replace the line below! - just testing 1st
// $xmlStr=str_replace("-",'—',$xmlStr);
return(htmlspecialchars(str_replace("#","<br /><br />",$htmlStr), ENT_QUOTES));
return $xmlStr;
}
index.php.txtread.php.txt
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have now fixed the issue regarding the ' & ' - thanks for your help.
However, the ' £ ' still won't display properly - at present it displays as a black diamond with a ' ? ' in the center! Do you have any further advice on this ?
Thanks again
However, the ' £ ' still won't display properly - at present it displays as a black diamond with a ' ? ' in the center! Do you have any further advice on this ?
Thanks again
No problem.
Uhm.. It's in the ISO 8859-1 (Latin-1) and shows fine on me. What encoding are you using/displaying on the site?
Uhm.. It's in the ISO 8859-1 (Latin-1) and shows fine on me. What encoding are you using/displaying on the site?
But you could always just use unicode encoding?
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
ASKER
Hmmm...not sure what encoding i am using - how does one tell?
I tried just adding:
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
to the <head></head> section of my main page (index.php) but this didn't seem to do anything!
I tried just adding:
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
to the <head></head> section of my main page (index.php) but this didn't seem to do anything!
It has to be before the <head> like:
<html>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<head>
..
Or just try old fashion iso 8859-1
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
ASKER
I'm afraid it's still not displaying the £ symbol correctly!
What other character sets could i try using?
What other character sets could i try using?
Have a look at what your browsers character encoding is? In firefox, for instance, View -> Character Encoding
ASKER
It is set to:
Unicode (UTF-8)
Unicode (UTF-8)
Then you should be able to view the character using both really. Can I get a link to the site you can't see properly and try myself?
ASKER
www.globexposure.net/index.php
Click on any pushpin marker > green arrow marker > icon
The £ symbol should display in the yellow box on the right-hand-side of the infowindow
Click on any pushpin marker > green arrow marker > icon
The £ symbol should display in the yellow box on the right-hand-side of the infowindow
Yeah, that doesm't work for me either.
Actually, £ ; is the same as £ ;
So I don't really get why it does not work..
Actually, £ ; is the same as £ ;
So I don't really get why it does not work..
ASKER
I agree it's a very strange problem. I will award you the points for the help you've given me and ask this question again i think with a link to this question and see if anyone else can see something we might have missed.
Thanks again
Thanks again
Thank you for the points! :)
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
should be in the head
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
should be in the head
ASKER
While we're on the subject however, is there a similar substitute for the £ symbol, which i currently try to catch as follows:
$xmlStr=str_replace('£','&
i'm currently testing with:
www.globexposure.net/includes/read_test.php