You are here

public function DatabaseConnection_sqlite::sqlFunctionSubstringIndex in Drupal 7

SQLite compatibility implementation for the SUBSTRING_INDEX() SQL function.

File

includes/database/sqlite/database.inc, line 213
Database interface code for SQLite embedded database engine.

Class

DatabaseConnection_sqlite
Specific SQLite implementation of DatabaseConnection.

Code

public function sqlFunctionSubstringIndex($string, $delimiter, $count) {

  // If string is empty, simply return an empty string.
  if (empty($string)) {
    return '';
  }
  $end = 0;
  for ($i = 0; $i < $count; $i++) {
    $end = strpos($string, $delimiter, $end + 1);
    if ($end === FALSE) {
      $end = strlen($string);
    }
  }
  return substr($string, 0, $end);
}