Advertisements

mb_substr

Definition:
function mb_substr($str, $start, $len = '', $encoding="UTF-8"){

Parameters

  • $str
  • $start
  • $len
  • $encoding

Source code

	function mb_substr($str, $start, $len = '', $encoding="UTF-8"){

		$limit = strlen($str);



		for ($s = 0; $start > 0;--$start) {// found the real start

			if ($s >= $limit)

				break;



			if ($str[$s] <= "\x7F")

				++$s;

			else {

				++$s; // skip length



				while ($str[$s] >= "\x80" && $str[$s] <= "\xBF")

					++$s;

			}

		}



		if ($len == '')

			return substr($str, $s);

		else

			for ($e = $s; $len > 0; --$len) {//found the real end

				if ($e >= $limit)

					break;



				if ($str[$e] <= "\x7F")

					++$e;

				else {

					++$e;//skip length



					while ($str[$e] >= "\x80" && $str[$e] <= "\xBF" && $e < $limit)

						++$e;

				}

			}



		return substr($str, $s, $e - $s);

	}

2341

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: