note 107588 modified in function.strstr by danbrown

From: Date: Thu, 10 May 2012 20:41:46 +0000
Subject: note 107588 modified in function.strstr by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187823@lists.php.net to get a copy of this message
I was in need of getting the first and last part of a string pre 5.3 so I wrote this:&#13;&#10;&#13;&#10;&#60;?php&#13;&#10;$fir = $first = explode( &#34; &#34;, $cmd[1] );&#13;&#10;unset( $fir[0] );&#13;&#10;$end = ltrim( implode( &#34; &#34;, $fir ) );&#13;&#10;?&#62;&#13;&#10;&#13;&#10;I needed it split with a &#34; &#34; but can obviously change for your needs. But with this format your output for the string:&#13;&#10;&#13;&#10;&#34;PHP is the best programming language out there&#34;&#13;&#10;&#13;&#10;Will give you the following results:&#13;&#10;&#13;&#10;&#60;?php&#13;&#10;$first[0] // PHP&#13;&#10;$end // is the best programming language out there&#13;&#10;?&#62;&#13;&#10;&#13;&#10;Works really well :) --was-- I was in need of getting the first and last part of a string pre 5.3 so I wrote this: <?php $fir = $first = explode( " ", $cmd[1] ); unset( $fir[0] ); $end = ltrim( implode( " ", $fir ) ); ?> I needed it split with a " " but can obviously change for your needs. But with this format your output for the string: "PHP is the best programming language out there" Will give you the following results: <?php $first[0] \\ PHP $end \\ is the best programming language out there ?> Works really well :) http://php.net/manual/en/function.strstr.php

« previous php.notes (#187823) next »