> -----Original Message----- > From: Ashley Sheridan [mailto:ash@xxxxxxxxxxxxxxxxxxxx] > Sent: Monday, February 23, 2015 11:23 PM > To: hadi > Cc: php-general@xxxxxxxxxxxxx > Subject: Re: strange character > > On Mon, 2015-02-23 at 23:13 +0300, hadi wrote: > > Im downloading feed from the internet. Im getting strange character > > (–) im not able to get rid of it. > > I tried to use preg_replace(). But not helping > > > > Here is my code > > > > <?php > > > > error_reporting(E_ALL); > > ini_set("display_errors", 1); > > > > > > require 'database.php'; > > > > $url = "http://www.sahafah.net/rss.php"; > > > > > > $rss = file_get_contents($url); > > > > ini_set('mbstring.substitute_character', "none"); $rss= > > mb_convert_encoding($rss, 'UTF-8', 'UTF-8'); > > > > $rss = simplexml_load_string($rss); > > > > > > if($rss) > > { > > $items = $rss->channel->item; > > foreach($items as $item) > > { > > > > $title = $item->title; > > $link = $item->link; > > $published_on = $item->pubDate; > > $description = $item->description; > > $category = $item->category; > > $guid = $item->guid; > > > > > > $pattern = "<"; > > > > $posfrist = strpos($item->description, $pattern); > > > > if($posfrist !== false) > > > > { > > preg_match('/.*</',$item->description,$match); > > $match1 = str_replace("<","",$match); > > echo '<pre>';print_r($match1);echo '</pre>'; > > > > $string2 = $item->description; > > preg_match('/http.*.jpg/',$string2,$match2); > > echo '<pre>';print_r($match2);echo '</pre>'; > > > > } > > } > > } > > > > > > > > > > > > > > ?> > > > > > > Hi Hadi, > > You've set the convert encoding on the feed you're getting, but there are a > couple of things to check. First, is the PHP script itself saved as UTF-8. If it > isn't, this can have an effect on the PHP parser where it attempts to guess > encodings of things. > > If you're seeing those characters output in your browser, it's probably also > worth checking that you've set a UTF-8 output header as well, otherwise it > defaults (typically) to something like ISO-8859-1. I tried to use http header but not helping header('Content-Type: text/html; charset=utf-8'); alos tried to save the file as utf-8, but not working.... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php