I am building an RSS feed, which is working, but my problem comes with the php in the feed I created. The story is a little complex but, you can check out the feed through a validator here: http://beta.feedvalidator.org/. The feed address to enter is www.craiggreenwood.com/feed.php. Here is the problem: I am being told "syntax error, unexpected '?' in <b>/home/craiggr/public ..." On further research my database has regular apostrophies in text, like "I'm going shopping and I'm going to be late." I know about functions like stripslashes and not sure if my problem is there or what. The section of code from the feed.php file looks like this: echo "<description>".strip_tags(substr($row['entry'],0,50))."...</description>\n"; Code (markup): One idea I had to use to addslashes to the datasource and then strip slashes on the way out, but I have my doubts about that as a plan. I've tried substr_replace and a host of other functions trying to control this. Does it have to do with my charset? I'm out of ideas and turning to the community on this. Thanks for your help. I am happy to provide more information if needed. Craig
Basicly substr() doesn´t work well with utf-8 since it´s 2 bytes/char in unicode... if it splits a char in half it will result in a "?".. I suspect this is what´s causing your problems.. What i did to solve that problem is splitting it into words, and using the standard that average word is approx 5 char long.. so in your case i would split it and return 10words for those 50 chars.
Thanks for your reply, I actually tried shortening the length of the substring. I posted 50 as my substring length because that's my goal. The problem is, one or two entries I have in the database start with the work "I've" or "We're". Which means the longest I can make the substr length is 1 character. This makes my RSS feed lack...um...panash! Would you recommend using a different char set? utf8 I landed on by suggestions from validators. I understand what charsets are, but boy, it seems like someone went out of their way to make them WAY more difficult than they need to be! All in the trade off between utility and speed I suppose. Thanks for your help on this so far! Craig
Actually I rather have full words but that´s just me, and after I made the function, I never ever have to make it again..
This is a personal blog I'm dealing with so the lanuage of the entries is casual text. Otherwise I would be all about doing away with the contractions. In this case I want to keep the contractions. That said I researched mb_substr and tried this: echo "<description>".strip_tags(mb_substr(str_replace(''',' ',$row['entry']),3,10))."...</description>\n"; Code (markup): This resulted in "syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in ..." I think my piling functions are starting to contradict themselves. Am I looking at a syntax error or something different? Craig
Hi, yes it is syntax error. You need to escape the single quote (or use double quote for the needle) : echo "<description>".strip_tags(mb_substr(str_replace('\'',' ',$row['entry']),3,10))."...</description>\n"; Code (markup):