For instance I want to implode these strings and prevent bad print

$a = "Apple in pesian( ";
$b="سیب";
$c=")use as a medicine for all illnesses";
print implode( " ", array( $a, $b, $c ) );

It's bad print
// use as a medicine for all illnesses( سیب )Apple in pesian

I want to print in this way
// Apple in pesian( سیب )use as a medicine for all illnesses

For instance I want to implode these strings and prevent bad print

$a = "Apple in pesian( ";
$b="سیب";
$c=")use as a medicine for all illnesses";
print implode( " ", array( $a, $b, $c ) );

It's bad print
// use as a medicine for all illnesses( سیب )Apple in pesian

I want to print in this way
// Apple in pesian( سیب )use as a medicine for all illnesses

Are you having problmes with the implode() function? Or is it the display of the characters in the browser?

A simple test would be:

Test Browser Display:

$a = "Apple in pesian( ";
$b="سیب";
$c=")use as a medicine for all illnesses";
print $a.' '.$b.' '.$c;

Test implode():

$a = "Apple in pesian( ";
$b="سیب";
$c=")use as a medicine for all illnesses";
print implode( " ", array( $a, $b, $c ) );

The problem could either be that you're not setting the encoding correctly. (The browser is not using the correct encoding to display the characters).

What encoding are you using by the way?

The other thing is that many php string functions do not handle multibyte encodings correctly. That is, the string functions do not handle characters in the string, just single bytes.

Eg: str_len() will actually return the number of bytes, not the number of encoded chars. So if you have a multibyte encoding on the string, str_len() will give you a larger length than that of the actual characters (that those bytes represent).

So you'll have to pick an encoding (UTF-8 being the recommended one) and take that encoding into regards when you call string functions.

Heres the link to the multibyte string functions.
http://www.php.net/mbstring

Heres a sorceforge project that provides utf8 aware string functions:
http://phputf8.sourceforge.net/

Heres a bit of info from PHP wiki on how they are moving to utf8 aware code.
http://phpwiki.sourceforge.net/phpwiki/Utf8Migration

Heres a bit on how Joomla is moving to utf8 aware code.
http://dev.joomla.org/index.php?option=com_jd-wiki&Itemid=31&id=guidelines:utf-8

btw:

Is $b="سیب"; displaying correctly on this page? because this page is utf-8 encoded, as far as firefox sees it.
If you see the same on your test page then your test page's encoding is ok, its just implode() that should be replaced with a multibyte encoding aware function..

Thanks for your convenient description.
I checked encocing of web page, it was UTF-8.In additon I have not any problem with the implode() function, it is just a new idea to place some words with a different language among an English sentence, also it is usefull for an accountancy program whic is web base

This article has been dead for over six months. Start a new discussion instead.