Link to home
Start Free TrialLog in
Avatar of Daniish
DaniishFlag for United Kingdom of Great Britain and Northern Ireland

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)


function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','&lt;',$htmlStr);
$xmlStr=str_replace('>','&gt;',$xmlStr);
$xmlStr=str_replace('"','&quot;',$xmlStr);
$xmlStr=str_replace("'",'&apos;',$xmlStr);
$xmlStr=str_replace("&",'&amp;',$xmlStr);
$xmlStr=str_replace('£','&pound;',$xmlStr);
$xmlStr=str_replace(chr(0x20).chr(0x10), '&#x2010;', $xmlStr);
// the line above should replace the line below! - just testing 1st
// $xmlStr=str_replace("-",'&mdash;',$xmlStr);
 
return(htmlspecialchars(str_replace("#","<br /><br />",$htmlStr), ENT_QUOTES));
return $xmlStr;
}

Open in new window

index.php.txt
read.php.txt
SOLUTION
Avatar of MortenSlotKristensen
MortenSlotKristensen
Flag of Denmark image

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
Avatar of Daniish

ASKER

I tried your change of code but it doesn't seem to make a difference.

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('£','&#163;',$xmlStr);

i'm currently testing with:
www.globexposure.net/includes/read_test.php
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
ASKER CERTIFIED 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
Avatar of Daniish

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
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?
But you could always just use unicode encoding?
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

Open in new window

Avatar of Daniish

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!
It has to be before the <head> like:
<html>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<head>
..

Open in new window

Or just try old fashion iso 8859-1
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

Open in new window

Avatar of Daniish

ASKER

I'm afraid it's still not displaying the £ symbol correctly!

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
Avatar of Daniish

ASKER

It is set to:

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?
Avatar of Daniish

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
Yeah, that doesm't work for me either.
Actually, &pound ; is the same as  &#163 ;
So I don't really get why it does not work..
Avatar of Daniish

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
Thank you for the points! :)
Avatar of Michel Plungjan
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">


should be in the head