<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6875055439293985287</id><updated>2012-02-16T04:30:39.979-08:00</updated><title type='text'>Share and Learn</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://learner-tops.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6875055439293985287/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://learner-tops.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Vasanth Govind</name><uri>http://www.blogger.com/profile/09422251735547922862</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='18' src='http://1.bp.blogspot.com/_bsBMW8KVHpo/SMgIoTlRBfI/AAAAAAAAAHc/KZiNJSX7DI0/S220/coustomRockstar.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6875055439293985287.post-7130351553775743409</id><published>2008-09-05T21:33:00.000-07:00</published><updated>2008-09-05T21:38:33.806-07:00</updated><title type='text'>strlen vs isset in PHP</title><content type='html'>  &lt;div&gt;  When working with strings and you need to check that the string is either of a certain length you’d understandably would want to use the strlen() function. This function is pretty quick since it’s operation does not perform any calculation but merely return the already known length of a string available in the zval structure (internal C struct used to store variables in PHP). However because strlen() is a function it is still somewhat slow because the function call requires several operations such as lowercase &amp;amp; hashtable lookup followed by the execution of said function. In some instance you can improve the speed of your code by using an isset() trick.&lt;span class="keyword"&gt;&lt;/span&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="keyword"&gt;      if&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class="func"&gt;strlen&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class="vars"&gt;$foo&lt;/span&gt;&lt;span&gt;) &lt; 5) { &lt;/span&gt;&lt;span class="func"&gt;echo&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class="string"&gt;"Foo is too short"&lt;/span&gt;&lt;span&gt;; } &lt;span class="keyword"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&lt;span class="keyword"&gt;      if&lt;/span&gt;&lt;span&gt; (!isset(&lt;/span&gt;&lt;span class="vars"&gt;$foo&lt;/span&gt;&lt;span&gt;{5})) { &lt;/span&gt;&lt;span class="func"&gt;echo&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span class="string"&gt;"Foo is too short"&lt;/span&gt;&lt;span&gt;; } &lt;/span&gt;&lt;/span&gt;&lt;pre style="display: none;" class="syntax-highlight:php"&gt;if (!isset($foo{5})) { echo "Foo is too short"; }&lt;/pre&gt; &lt;p&gt;Calling isset() happens to be faster then strlen() because unlike strlen(), isset() is a language construct and not a function meaning that it’s execution does not require function lookups and lowercase. This means you have virtually no overhead on top of the actual code that determines the string’s length. &lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6875055439293985287-7130351553775743409?l=learner-tops.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learner-tops.blogspot.com/feeds/7130351553775743409/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6875055439293985287&amp;postID=7130351553775743409' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6875055439293985287/posts/default/7130351553775743409'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6875055439293985287/posts/default/7130351553775743409'/><link rel='alternate' type='text/html' href='http://learner-tops.blogspot.com/2008/09/strlen-vs-isset-in-php.html' title='strlen vs isset in PHP'/><author><name>Vasanth Govind</name><uri>http://www.blogger.com/profile/09422251735547922862</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='18' src='http://1.bp.blogspot.com/_bsBMW8KVHpo/SMgIoTlRBfI/AAAAAAAAAHc/KZiNJSX7DI0/S220/coustomRockstar.jpg'/></author><thr:total>0</thr:total></entry></feed>
