[SOLVED]PHP Generating Odd Characters

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mtheoryninja
Forum Newbie
Posts: 3
Joined: Fri Aug 20, 2010 10:07 pm

[SOLVED]PHP Generating Odd Characters

Post by mtheoryninja »

Hey everyone, I'm using some PHP code I gleaned off the web which is meant to parse RSS feeds. I've been editing it to display that which I wish, yet I've hit a bump.

In order to see what problem I'm having please see: http://www.boaty.wildspad.com/mtheoryninja
Here's is the RSS source: http://www.watchtheguild.com/feed/

As you can see, the RSS Feed shows 'The Guild', yet the website shows ‘The Guild’.

Here's the PHP that I'm using

Code: Select all

	function show(){
		if($this->title){
			if($this->link){
				echo "<a href=\"$this->link\">$this->title</a>\n";
			}elseif($this->title){
				echo "$this->title</a>\n";
			}
			if($this->pubdate)
				echo "<br /><i>$this->pubdate</i><br />";
			echo "\n";
		}
	}
The full source code can be found at http://www.boaty.wildspad.com/mtheoryni ... reader.txt

I have no PHP experience, although I've used knowledge of other programming languages to help me edit this code so far. I'm sure what I'm asking is simple, yet never having used PHP, I don't know what it is.

Thanks in advance for any help which can be given.
Last edited by mtheoryninja on Sat Aug 21, 2010 6:15 am, edited 1 time in total.
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: PHP Generating Odd Characters

Post by internet-solution »

These are smart quote characters. You can try this code to remove them (source: http://php.net/manual/en/function.str-replace.php)

Code: Select all

<?php
  $find[] = '“';  // left side double smart quote
  $find[] = '”';  // right side double smart quote
  $find[] = '‘';  // left side single smart quote
  $find[] = '’';  // right side single smart quote
  $find[] = '…';  // elipsis
  $find[] = '—';  // em dash
  $find[] = '–';  // en dash

  $replace[] = '"';
  $replace[] = '"';
  $replace[] = "'";
  $replace[] = "'";
  $replace[] = "...";
  $replace[] = "-";
  $replace[] = "-";

  $text = str_replace($find, $replace, $text);
?>
mtheoryninja
Forum Newbie
Posts: 3
Joined: Fri Aug 20, 2010 10:07 pm

Re: PHP Generating Odd Characters

Post by mtheoryninja »

Thanks for the code and link. I've been playing around with it, yet the error still remains.

Current bit of code

Code: Select all

class newsStory{
	var $title="";
	var $link="";
	var $description="";
	var $pubdate="";
	
	function show(){
		if($this->title){
			$find[]='“';  // left side double smart quote
			$find[]='”';  // right side double smart quote
			$find[]='‘';  // left side single smart quote
			$find[]='’';  // right side single smart quote
			$find[]='…';  // elipsis
			$find[]='—';  // em dash
			$find[]='–';  // en dash
			
			$replace[]='"';
			$replace[]='"';
			$replace[]="'";
			$replace[]="'";
			$replace[]="...";
			$replace[]="-";
			$replace[]="-";

			$title=str_replace($find, $replace, $title);

			if($this->link){
				echo "<a href=\"$this->link\">$this->title</a>\n";
			}elseif($this->title){
				echo "$this->title</a>\n";
			}
			if($this->pubdate)
				echo "<br /><i>$this->pubdate</i><br />";
			echo "\n";
		}
	}
}
Links above are still valid for rssreader.php and the website itself.

Thanks for the help; I'm going back to playing with it some more.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP Generating Odd Characters

Post by requinix »

Rather than removing them, how about, you know, keeping them?

Code: Select all

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
or

Code: Select all

header("Content-Type: text/html; charset=utf-8");
mtheoryninja
Forum Newbie
Posts: 3
Joined: Fri Aug 20, 2010 10:07 pm

Re: PHP Generating Odd Characters

Post by mtheoryninja »

Thanks Tasairis; worked wonderfully.
Post Reply