note 94463 modified in function.strtok by danbrown

From: Date: Fri, 06 Nov 2009 14:56:56 +0000
Subject: note 94463 modified in function.strtok by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162447@lists.php.net to get a copy of this message
Simple way to tokenize search parameters, including double or single quoted keys. If only one quote is found, the rest of the string is assumed to be part of that token. <?php $token = strtok($keywords,' '); while ($token) { // find double quoted tokens if ($token{0}=='"') { $token .= ' '.strtok('"').'"'; } // find single quoted tokens if ($token{0}=="'") { $token .= ' '.strtok("'")."'"; } $tokens[] = $token; $token = strtok(' '); } ?> Use substr(1,strlen($token)) and remove the part that adds the trailing quotes if you want your output without quotes. --was-- Simple way to tokenize search parameters, including double or single quoted keys. If only one quote is found, the rest of the string is assumed to be part of that token. $token = strtok($keywords,' '); while ($token) { // find double quoted tokens if ($token{0}=='"') { $token .= ' '.strtok('"').'"'; } // find single quoted tokens if ($token{0}=="'") { $token .= ' '.strtok("'")."'"; } $tokens[] = $token; $token = strtok(' '); } Use substr(1,strlen($token)) and remove the part that adds the trailing quotes if you want your output without quotes. http://php.net/manual/en/function.strtok.php

« previous php.notes (#162447) next »