Jump to content

Recommended Posts

I am trying to get a DESCRIPTION for my RSS feed but there are too many special characters in the description for it to display properly.

 

Is there any code that will replace everything??

 

I have tried::::

htmlentities()

addslashes()

htmlspecialchars()

 

The problem is there are way too many special characters in my description to just replace each one of them...

And not one of the above will do the job....

 

Stuff like::

 

¼

ö

 

and a lot more....

 

I would just replace the ones I find as I go.. but that won't stop future descriptions from having more characters that I did not account for making my RSS feed messed up.

 

 

Should I combine them all...??

htmlentities(htmlspecialchars(DESCRIPTION));

 

Or something like that...???

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/69653-solved-help-with-character-replacement/
Share on other sites

Tried it... but it doesn't work....

 

".htmlentities(htmlspecialchars(trim($data['DESCRIPTION'])))."

 

Still too many special characters not accounted for with those functions....

 

Isn't there a function that will strip ALL special characters?

 

 

Like I said if I try to replace them all it would be impossible to prevent future descriptions from containing what I had missed........

I tried this and it still doesn't do the job....

mysql_real_escape_string(htmlentities(htmlspecialchars(trim($_POST[description]))))

 

So it looks like I'll just leave the description out of the feed then....

Because they use everything from foreign language characters to stuff I have never seen

and it would take weeks to write a replacement for everything in these descriptions... (over 15,000 descriptions with tons of characters to replace)

 

So there is no "SOLVED" for this one... since there doesn't seem to be a function that will replace everything but letters in the english alphabet...

 

and the description doesn't look right with stuff like this in there for people to see.. ¼

 

 

I guess you could take each word within the description and use some regex on it and then only return the word if its normal

 

EDIT: You could then check each letter of the dodgy word and remove it if its bad, this would be sloppy but could work

 

~ Chocopi

darkfreaks..

Yes I could do that... but that means I would have a million replacements...

and I would have to dig through 15,000 descriptions once a week in order to have them display properly...

 

I am creating over 400 individual feeds..  and there would always be one character that messed up one of them...

so it would be way too time consuming to monitor and keep up to date...

 

I just thought that there would be a function that would replace everything in one shot...

But it seems that there are not enough PREDEFINED characters in any replace function...

 

So my best and easiest option would be to leave the description out of the feed all together...

I am trying to remove them all...

 

They are fine in PHP but in an XML feed they make the feed have errors and not display at all...

Everything is fine in the XML feed until it finds a character that I cannot seem to replace or remove...

NEW to PHP so I have no idea what character set the feed is in....

 

 

BUT....

That DID Work perfectly....

 

I knew there had to be some way to do it....

 

Thanks for sticken with me on this one...!!!!!!

 

GREATLY APPRECIATED....!!

Now that the feed is displaying properly..  I am only going to include around 100 characters of the description

so as long as the feed actually displays.. the users don't really need to see those special charcters any way...

 

So...

 

SOLVED!!!

 

Thanks Again...

When I learn more I'll participate and help others as well...

;D

well just to improve on $username's code

 

<?php
$desc = // your rss stuff
$desc = ereg_replace("[^ A-Za-z0-9.;:@?!\"£$%^&*()-_=+'<>/\\[\]\{\}]","",$desc);
echo $desc;
?>

 

I think thats all the basic keys on the standard english keyboard.

 

~ Chocopi

effigy

I am creating the feeds and yes the first line is

<?xml version="1.0" encoding="utf-8"?>

 

I just didn't know where to look.......  LOL... total noob...

 

Chocopi

Thanks for the "more info....."

 

-----------

I did want to add that this place is a FREAKIN GOLD MINE of knowledge...

For the past few months I have done nothing but read books and learn on my own... nice to have a place to ask questions I can't find the answers to..!

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.