Jump to content

XML Feed and Stripping Characters


dswain

Recommended Posts

Hey everyone. I'm pretty new here, and I'm fairly new to PHP in general, so I'm totally open to whatever you guys have to suggest. Anyway, here's what I'm trying to work on today:

 

I have an RSS feed and I'm using PHP to output it onto my website. I have most of what I want working, except for one issue: http://swainnet.zapto.org/rss.php if you look here, you'll see that it shows that strange "–" character: in the XML, it looks as if it's suppose to be a dash. I tried to change the encoding of the XML parser trying something like this:

 

<?php
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
xml_set_element_handler($parser,"startTag","endTag");
xml_set_character_data_handler($parser,"readTag");?>

 

And I've set that to a variety of things (like US-ASCII, ISO-8859-1) but these changes had no effect. I also tried to strip the dash out with a strrpos and trim, but it seems to be acting like the character doesn't exist within the string. I also tried search for the strange character using strrpos, but it can't seem to find that either. Are there any ideas on what I may be doing wrong or what else I should look for? Thanks in advanced everyone.

 

Oh and my code can be found here (if needed): http://swainnet.zapto.org/rss.txt

Link to comment
https://forums.phpfreaks.com/topic/40050-xml-feed-and-stripping-characters/
Share on other sites

Hm, no, I didn't. I just tried it now. I believe I have the syntax correct:

 

$parser = xml_parser_create('UTF-8');

but that does not seem to have an effect either. I also tried to just leave it quoted (with no actual argument) and no luck with that either.

Actually, since this page contains data encoded in UTF-8, the meta tag should say so: <meta charset="utf-8"/>. If you still want to strip or replace the data, you can use regular expressions:

 

$string = preg_replace('/\xe2\x80\x93/', '-', $string);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.