Задать вопрос
Ответы пользователя по тегу PHP
  • Как распознать кодировку?

    ezh
    @ezh
    <?php
    $line = '0:00.03 php yiic.php route preloadRoute --busNumber=887M-PM-%';
    if (!preg_match('#--busNumber=([^-]*)#', $line, $matches)) die("does not match\n");
    echo $matches[1], "\n";
    Ответ написан
    Комментировать
  • Как обработать определённые значения memcache?

    ezh
    @ezh
    <?php
    class People implements IteratorAggregate {
        private $c;
        public function __construct($host, $port) {
            // TODO handle errors
            $this->c = memcache_connect($host, $port);
        }
        public function add($id, $value) {
            memcache_set($this->c, "people_$id", $value);
            // TODO race condition
            $list = memcache_get($this->c, "peoples");
            $list[$id] = true;
            memcache_set($this->c, "peoples", $list);
        }
        public function getIterator() {
            $list = memcache_get($this->c, "peoples");
            foreach ($list as $item => $_) yield memcache_get($this->c, "people_$item");
        }
    }
    $People = new People('localhost', 11211);
    $People->add(1112, "first");
    $People->add(1115, shell_exec("uname -v"));
    $People->add(2000, microtime(true));
    foreach ($People as $item) {
        echo $item, "\n";
    }
    Ответ написан
    Комментировать