views:

153

answers:

2

I am using a shared hosting service to host my site so I can't get direct access to PHP configuration or install any extension. So my problem is with utf-8 strings that can't be processed by standard PHP string functions since I don't have mbstring extension installed on the server. I am looking for another way to deal with unicode strings, any help or guidance is very appreciated or if you know of any online resources please share them with me.

+5  A: 

There is the PHP UTF-8 library up there at Sourceforge - might be enough for your needs. Also, preg_* functions generally accept the /u modifier independently of mbstring.

On the long term I'd agree it's time to start looking around for a more up-to-date host. Mbstring is pretty much a basic necessity today, with a host lacking this one has to ask what else might be missing.

djn
+2  A: 

if you've no choice but to stick with this host and you can't twist their arms into providing mbstring (c'mon, php w/o mbstring is, like, sooo 1999[*]) then can you use the intl pecl extension? that plus what you can do with PCRE and iconv might suffice.

intl has, apart from formatters and the handy collator, these grapheme functions:

  • grapheme_extract — Function to extract a sequence of default grapheme clusters from a text buffer, which must be encoded in UTF-8.

  • grapheme_stripos — Find position (in grapheme units) of first occurrence of a case-insensitive string

  • grapheme_stristr — Returns part of haystack string from the first occurrence of case-insensitive needle to the end of haystack.

  • grapheme_strlen — Get string length in grapheme units

  • grapheme_strpos — Find position (in grapheme units) of first occurrence of a string

  • grapheme_strripos — Find position (in grapheme units) of last occurrence of a case-insensitive string

  • grapheme_strrpos — Find position (in grapheme units) of last occurrence of a string

  • grapheme_strstr — Returns part of haystack string from the first occurrence of needle to the end of haystack.

  • grapheme_substr — Return part of a string

[*] apologies for the teenspeak

fsb