Jump to content

[SOLVED] html_entity_decode()


SharkBait

Recommended Posts

I am having some issues with a RSS Feed creation script I have.

 

The entries that are to go into the RSS feed have ampersands in them like   or « or » and being RSS I believe they are not allowed to have ampersands in them (or so the RSS 2.0 Specification told me).

 

Now I use

html_entity_decode()

and I thought that is supposed to convert things back to their proper character.  Am I incorrect? Am I getting that function and

htmlentities()

confused?

 

This is the bit of code I am using:

<?php

while($blog = mysql_fetch_array($query, MYSQL_ASSOC)) {
// Strip HTML tags and convert any special characters
$description = $blog['body'];
$description = html_entity_decode($description);

// Modify date to RFC 822 Specification
$pubDate = date("D, d M Y H:i:s T", strtotime($blog['date_entered']));

// encode URL with - so that it is URL friendly (for Mod_rewrite)
$url = str_replace(" ", "-", $blog['title']);

// Actual body of the feed. Gets looped though and created for each Blog Entry

$feed =  "<item>\n
			<title>{$blog['title']}</title>\n
			<description>{$description}</description>\n
			<link>http://www.tingram.ca/blog/{$url}</link>\n
			<pubDate>{$pubDate}</pubDate>\n
			<guid>http://www.tingram.ca/blog/{$url}</guid>\n
			</item>\n\n";

// Write the current Blog Entry to the file
fwrite($file, $feed);
}

?>

 

Any help is great!

 

 

Link to comment
Share on other sites

Ok so I read up on the internal and external entities.

 

Now the code above will not convert the   or « entities properly so when they get loaded into the XML file they crap out and the XML document won't display.

 

How do I handle things like & etc when they are within the body of the RSS feed?  Or am I not understanding what it is I need to do with my database information prior to loading it into an XML file?

Link to comment
Share on other sites

I know in another post in regards to html entities, there was a custom function

 

http://www.phpfreaks.com/forums/index.php/topic,128079.0.html

You will find someone that made entity safe functions, maybe that will help.

 

Try that out, if not explain that is happening exactly.  Is it encoding when you are not wanting it to, or vice-versa. (Sorry if it's spelt wrong).

 

Link to comment
Share on other sites

Hi, I was just concerned and wondering if you solved your problem yesterday or not.  Let  us know here if you didn't I can try and help more, maybe someone else will have ideas.  WHere do you stand with your current problem right now, I don't want you just stuck here without an answer, you have helped me many times, I like the opprotunity to return the favor.  So did you fix it, or are you still having problems with it?

Link to comment
Share on other sites

I figured out what the solution is for my problem. I had to tell the XML parser to ignore the data within my <description> tags!

 

I was looking over the Wordpress scripts and that is what tipped me off!

 

<?php

<description><!CDATA[{$description}]]></description>

?>

 

Explaination: http://www.w3schools.com/xml/xml_cdata.asp

 

Yay I'm soo happy I figured it out now I can use Full RSS Feeds with html formatting!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.