[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

£ is an invalid entity - what do i replace it with ?

Posted on 2008-11-05
6
Medium Priority
?
297 Views
Last Modified: 2012-05-05
Hello,

I use the attached code to catch invalid entities from data held in mysql. I would like to add a line to this code to catch the pound symbol ' £ '

What should this be replaced with?

Where can i find a complete list of valid entities in case i need to add any other dodgy characters ?


Many thanks
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(chr(0x20).chr(0x10), '&#x2010;', $xmlStr);
return(htmlspecialchars(str_replace("#","<br /><br />",$htmlStr), ENT_QUOTES));
return $xmlStr;
}

Open in new window

0
Comment
Question by:Daniish
6 Comments
 
LVL 6

Accepted Solution

by:
cr4ck3rj4ck earned 1000 total points
ID: 22888458
This should work for you:

$xmlStr=str_replace('£','&pound;',$xmlStr);

Open in new window

0
 
LVL 6

Assisted Solution

by:cr4ck3rj4ck
cr4ck3rj4ck earned 1000 total points
ID: 22888467
For additional characters, check out: http://www.ascii.cl/htmlcodes.htm
0
 
LVL 82

Assisted Solution

by:hielo
hielo earned 500 total points
ID: 22888494
replace it with:

&#163; 
the friendly name is not a "standard" xml entity.

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 11

Assisted Solution

by:NoiS
NoiS earned 500 total points
ID: 22889100
First

htmlspecialchars don't convert all chars, just a few like < >;

Use htmlentities instead.

Second
Everytime that you need special chars inside a XML use CDATA

<tag><![CDATA[YOUR CONTENTS GOES HERE]]></tag>
0
 

Author Comment

by:Daniish
ID: 22893521
Thank you all for your suggestions - i have tried both of the following:

$xmlStr=str_replace('£','&#163;',$xmlStr);
$xmlStr=str_replace('£','&pound;',$xmlStr);

but neither have the desired effect, what could be going wrong ?

If you wish to see the currently unconverted symbols - please visit:
www.globexposure.net/index.php
Then click on the England pushpin marker > the Norwich (SE England) Arrow marker > airplane icon
You will see in the right hand column that 3x £ symbols aren't being displayed!


Thanks again

p.s. excellent link cr4ck3rj4ck :)
0
 

Author Closing Comment

by:Daniish
ID: 31513625
I forgot to apply the replacement of special characters to the individual attributes being returned from my database - all sorted now.

Many thanks :)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month18 days, 12 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question