homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Alternatives to iconv()

Msg#: 4655203 posted 1:09 am on Mar 19, 2014 (gmt 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:


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?



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

Msg#: 4655203 posted 1:07 am on Mar 22, 2014 (gmt 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?


Msg#: 4655203 posted 8:25 am on Apr 9, 2014 (gmt 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.


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

Msg#: 4655203 posted 12:49 pm on Apr 18, 2014 (gmt 0)

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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved