Bolt\Helpers\Str::replaceFirst PHP Method

replaceFirst() public static method

Replace the first occurence of a string only. Behaves like str_replace, but replaces _only_ the _first_ occurence.
See also: http://stackoverflow.com/a/2606638
public static replaceFirst ( string $search, string $replace, string $subject ) : string
$search string
$replace string
$subject string
return string
    public static function replaceFirst($search, $replace, $subject)
    {
        $pos = strpos($subject, $search);
        if ($pos !== false) {
            $subject = substr_replace($subject, $replace, $pos, strlen($search));
        }
        return $subject;
    }

Usage Example

Beispiel #1
0
 /**
  * Event fired on database connection failure.
  *
  * @param FailedConnectionEvent $args
  *
  * @throws BootException
  */
 public function failConnect(FailedConnectionEvent $args)
 {
     $e = $args->getException();
     $this->logger->debug($e->getMessage(), ['event' => 'exception', 'exception' => $e]);
     /*
      * Using Driver here since Platform may try to connect
      * to the database, which has failed since we are here.
      */
     $platform = $args->getDriver()->getName();
     $platform = Str::replaceFirst('pdo_', '', $platform);
     $response = $this->exceptionController->databaseConnect($platform, $e);
     throw new BootException($e->getMessage(), $e->getCode(), $e, $response);
 }
All Usage Examples Of Bolt\Helpers\Str::replaceFirst