Welcome to WebmasterWorld Guest from 54.166.123.247

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Alternatives to iconv()

     
1:09 am on Mar 19, 2014 (gmt 0)

Junior Member

joined:Jan 9, 2014
posts: 150
votes: 0


I'm moving everything to a new server. The old server used PHP v. 5.2.17, and the new one is 5.4.25.

One function I used fairly often when importing content from another site was iconv(), like so:

$var = iconv("UTF-8", "ISO-8859-1//IGNORE", $var);

On the new server, though, this is returning false (or maybe just empty), leaving me with nothing but a blank variable. If I remove the line, everything is fine, so iconv() is definitely the problem.

I did a little digging, and found that iconv() does have a bug specifically when using //IGNORE, but unfortunately for me, that's pretty important:

[bugs.php.net...]

I tried the recommended fix, which didn't give any errors, but didn't convert anything, either:

ini_set('mbstring.substitute_character', "none");
$text= mb_convert_encoding($text, 'UTF-8', 'ISO-8859-1');

I don't exactly want to use ini_set() on so many scripts, anyway, so I still don't know if this is the best choice.

Can you guys recommend an alternative to iconv() that would accomplish the same thing?
1:07 am on Mar 22, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2006
posts: 3123
votes: 0


Have you tried
mb_substitute_character("none")
instead of
ini_set()
?

Do you have an example of the content you are trying to convert/import?
8:25 am on Apr 9, 2014 (gmt 0)

Junior Member

joined:Jan 9, 2014
posts: 150
votes: 0


I'm importing RSS from Yahoo News. When it comes in, I occasionally get something like this:

PHILADELPHIA — All Ryan Braun needed to shake his slump was a trip to Philadelphia.

I'm trying to convert the — to something recognizable, or at least a whitespace.

I'm currently getting away with this by using:

$text = str_replace(array('—', '’', '?'), ' ', $text);

But of course, this isn't ideal at all, since more odd characters can show up without notice.
12:49 pm on Apr 18, 2014 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12547
votes: 2


Question: rather than convert the characters why not just use utf-8 to store and display them?

If this is not possible you may need to check your locale before the conversion.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members