String::insert PHP Method

insert() public static method

public static insert ( $string, $data )
    public static function insert($string, $data)
    {
        asort($data);
        foreach ($data as $key => $value) {
            $regex = '%(:' . $key . ')%';
            $string = preg_replace($regex, $value, $string);
        }
        return $string;
    }

Usage Example

Example #1
0
 function install()
 {
     if (empty($this->args)) {
         return $this->main();
     }
     $args = $this->args;
     if (!empty($args[0]) && $args[0] == 'all') {
         $this->_getFiles();
         $args = $this->files;
     }
     if (!empty($this->params['f'])) {
         $this->args = $args;
         $this->uninstall();
     }
     foreach ($args as $arg) {
         if ($sql = $this->_getFile($arg)) {
             $sql = String::insert($sql, array('prefix' => $this->Db->tablePrefix), array('before' => '{', 'after' => '}', 'clean' => true));
             $this->Db->query($sql);
             $this->out('OK: ' . $arg . ' created');
         } else {
             $this->out($arg . ' not found');
         }
     }
     $this->out('... done');
 }
All Usage Examples Of String::insert