<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: UTF-8 and strlen()</title>
	<atom:link href="http://eatmymonkeydust.com/2008/04/utf-8-and-strlen/feed/" rel="self" type="application/rss+xml" />
	<link>http://eatmymonkeydust.com/2008/04/utf-8-and-strlen/</link>
	<description>Life, PHP and Symfony - straight from the monkey's mouth</description>
	<lastBuildDate>Wed, 04 Apr 2012 14:42:13 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: praca</title>
		<link>http://eatmymonkeydust.com/2008/04/utf-8-and-strlen/comment-page-1/#comment-206</link>
		<dc:creator>praca</dc:creator>
		<pubDate>Tue, 02 Sep 2008 13:41:24 +0000</pubDate>
		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=9#comment-206</guid>
		<description>isset() is a language construction and not a function, than is 2-10 times faster than strlen() function.

$foo = &#039;same_string&#039;;

isset($foo{4}) == isset($foo[4]) but in PHP6 corect is isset($foo[4])</description>
		<content:encoded><![CDATA[<p>isset() is a language construction and not a function, than is 2-10 times faster than strlen() function.</p>
<p>$foo = &#8216;same_string&#8217;;</p>
<p>isset($foo{4}) == isset($foo[4]) but in PHP6 corect is isset($foo[4])</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Plamenator</title>
		<link>http://eatmymonkeydust.com/2008/04/utf-8-and-strlen/comment-page-1/#comment-91</link>
		<dc:creator>Plamenator</dc:creator>
		<pubDate>Wed, 25 Jun 2008 18:55:32 +0000</pubDate>
		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=9#comment-91</guid>
		<description>thanks, man! phew, finally fixed my length! :D</description>
		<content:encoded><![CDATA[<p>thanks, man! phew, finally fixed my length! <img src='http://eatmymonkeydust.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zegenie</title>
		<link>http://eatmymonkeydust.com/2008/04/utf-8-and-strlen/comment-page-1/#comment-30</link>
		<dc:creator>zegenie</dc:creator>
		<pubDate>Fri, 18 Apr 2008 12:59:32 +0000</pubDate>
		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=9#comment-30</guid>
		<description>Yeah, I figured as much, just didn&#039;t want to spam your comments ;) mp_strlen works, but with multibyte strings, using isset() is a no go.</description>
		<content:encoded><![CDATA[<p>Yeah, I figured as much, just didn&#8217;t want to spam your comments <img src='http://eatmymonkeydust.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  mp_strlen works, but with multibyte strings, using isset() is a no go.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Russ</title>
		<link>http://eatmymonkeydust.com/2008/04/utf-8-and-strlen/comment-page-1/#comment-29</link>
		<dc:creator>Russ</dc:creator>
		<pubDate>Fri, 18 Apr 2008 07:09:12 +0000</pubDate>
		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=9#comment-29</guid>
		<description>You should try 

echo mb_strlen($fu, &#039;UTF-8&#039;);

I had to specify the encoding because it didn&#039;t automatically recognise it...</description>
		<content:encoded><![CDATA[<p>You should try </p>
<p>echo mb_strlen($fu, &#8216;UTF-8&#8242;);</p>
<p>I had to specify the encoding because it didn&#8217;t automatically recognise it&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zegenie</title>
		<link>http://eatmymonkeydust.com/2008/04/utf-8-and-strlen/comment-page-1/#comment-28</link>
		<dc:creator>zegenie</dc:creator>
		<pubDate>Thu, 17 Apr 2008 18:41:03 +0000</pubDate>
		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=9#comment-28</guid>
		<description>btw, I tried with both (isset($fu{4})) and (isset($fu[4])), same results.</description>
		<content:encoded><![CDATA[<p>btw, I tried with both (isset($fu{4})) and (isset($fu[4])), same results.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zegenie</title>
		<link>http://eatmymonkeydust.com/2008/04/utf-8-and-strlen/comment-page-1/#comment-27</link>
		<dc:creator>zegenie</dc:creator>
		<pubDate>Thu, 17 Apr 2008 18:39:21 +0000</pubDate>
		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=9#comment-27</guid>
		<description>Interesting use of isset(), like Russ said. Never seen that one before. It made me have a look and try.

I tested when saving my document as ISO-8859-15 (norwegian) and (UTF-8). The results:

$fu = &#039;æøå&#039;;
echo strlen($fu); // 8859-15: length 3, UTF-8: length 6;
echo mb_strlen($fu); // 8859-15: length 3, UTF-8: length 6 (&lt;--shouldn&#039;t this be 3?);
echo (isset($fu[4])) ? &#039;yes&#039; . $fu[4] : &#039;no&#039;; // 8859-15: &#039;no&#039;, UTF-8: &#039;yesÃ&#039;;

So, honestly, it didn&#039;t work either way ... Maybe my PHP isn&#039;t compiled with mb_*** support?</description>
		<content:encoded><![CDATA[<p>Interesting use of isset(), like Russ said. Never seen that one before. It made me have a look and try.</p>
<p>I tested when saving my document as ISO-8859-15 (norwegian) and (UTF-8). The results:</p>
<p>$fu = &#8216;æøå&#8217;;<br />
echo strlen($fu); // 8859-15: length 3, UTF-8: length 6;<br />
echo mb_strlen($fu); // 8859-15: length 3, UTF-8: length 6 (&lt;&#8211;shouldn&#8217;t this be 3?);<br />
echo (isset($fu[4])) ? &#8216;yes&#8217; . $fu[4] : &#8216;no&#8217;; // 8859-15: &#8216;no&#8217;, UTF-8: &#8216;yesÃ&#8217;;</p>
<p>So, honestly, it didn&#8217;t work either way &#8230; Maybe my PHP isn&#8217;t compiled with mb_*** support?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Russ</title>
		<link>http://eatmymonkeydust.com/2008/04/utf-8-and-strlen/comment-page-1/#comment-16</link>
		<dc:creator>Russ</dc:creator>
		<pubDate>Wed, 16 Apr 2008 11:28:40 +0000</pubDate>
		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=9#comment-16</guid>
		<description>How does that work with multi-byte characters though? 

I would assume that isset($string{100}) is counting Bytes, which would cause problems with out UTF-8 dilema.

Perhaps combined with a call to utf8_decode() it could work, but then that could be more expensive than using mb_stlen()...

All interesting though, I&#039;ve never seen isset() used like that, and I&#039;m surprised that it is not mentioned in the comments on the PHP site on either isset() or strlen().</description>
		<content:encoded><![CDATA[<p>How does that work with multi-byte characters though? </p>
<p>I would assume that isset($string{100}) is counting Bytes, which would cause problems with out UTF-8 dilema.</p>
<p>Perhaps combined with a call to utf8_decode() it could work, but then that could be more expensive than using mb_stlen()&#8230;</p>
<p>All interesting though, I&#8217;ve never seen isset() used like that, and I&#8217;m surprised that it is not mentioned in the comments on the PHP site on either isset() or strlen().</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://eatmymonkeydust.com/2008/04/utf-8-and-strlen/comment-page-1/#comment-15</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Wed, 16 Apr 2008 11:21:29 +0000</pubDate>
		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=9#comment-15</guid>
		<description>Hi Russ,

strlen() is one of most expensive functions so if You want find out if string has more than 100 chars You can do:

if (isset($string{100})) {
    echo &#039;String is longer than 10 chars&#039;;
}

isset() is not a function - it&#039;s language construct - so it works faster than usually functions and isset() doesn&#039;t have to count all $string one by one char.</description>
		<content:encoded><![CDATA[<p>Hi Russ,</p>
<p>strlen() is one of most expensive functions so if You want find out if string has more than 100 chars You can do:</p>
<p>if (isset($string{100})) {<br />
    echo &#8216;String is longer than 10 chars&#8217;;<br />
}</p>
<p>isset() is not a function &#8211; it&#8217;s language construct &#8211; so it works faster than usually functions and isset() doesn&#8217;t have to count all $string one by one char.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Russ</title>
		<link>http://eatmymonkeydust.com/2008/04/utf-8-and-strlen/comment-page-1/#comment-14</link>
		<dc:creator>Russ</dc:creator>
		<pubDate>Wed, 16 Apr 2008 11:08:50 +0000</pubDate>
		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=9#comment-14</guid>
		<description>Hi Mike,

I&#039;m not sure why you think that would work, since isset() only returns true or false.

http://php.net/isset

Perhaps you have misunderstood? Or maybe there is another way to use isset() which you can elaborate on :o)</description>
		<content:encoded><![CDATA[<p>Hi Mike,</p>
<p>I&#8217;m not sure why you think that would work, since isset() only returns true or false.</p>
<p><a href="http://php.net/isset" rel="nofollow">http://php.net/isset</a></p>
<p>Perhaps you have misunderstood? Or maybe there is another way to use isset() which you can elaborate on <img src='http://eatmymonkeydust.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://eatmymonkeydust.com/2008/04/utf-8-and-strlen/comment-page-1/#comment-13</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Wed, 16 Apr 2008 10:36:32 +0000</pubDate>
		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=9#comment-13</guid>
		<description>Best way to validate string length is isset() function not strlen().</description>
		<content:encoded><![CDATA[<p>Best way to validate string length is isset() function not strlen().</p>
]]></content:encoded>
	</item>
</channel>
</rss>

