Рабочая тетрадь(4)
.pdf int preg_match_all ( string $pattern ,
string $subject , array $&matches [, int $flags [, int $offset ]] )
preg_match_all("|<[^>]+>(.*)</[^>]+>|U", "<b>example: </b><div align=left>this is a test </div>", $out, PREG_PATTERN_ORDER);
echo $out[0][0] . ", " . $out[0][1] . "\n"; echo $out[1][0] . ", " . $out[1][1] . "\n";
▪<b>example: </b>, <div align=left>this is a test</div>
▪example: , this is a test
PREG_SET_ORDER
▪<b>example: </b>, example:
▪<div align="left">this is a test</div>, this is a test
mixed preg_replace ( mixed $pattern ,
mixed $replacement , mixed $subject [, int $limit ] )
$string = "April 15, 2003";
$pattern = "/(\w+) (\d+), (\d+)/i";
$replacement = "\${1}1,\$3";
echo preg_replace($pattern, $replacement,
$string);
preg_replace('/(<\/?)(\w+)([^>]*>)/e', "'$1'.strtoupper('$2').'$3'",
$html_body);
array preg_split ( string $pattern , string $subject
[, int $limit [, int $flags ]] )
$keywords = preg_split("/[\s,]+/",
"hypertext language, programming");
$str = 'string';
$chars = preg_split('//', $str, -1,
PREG_SPLIT_NO_EMPTY);
$str = 'hypertext language programming'; $chars = preg_split('/ /', $str, -1,
PREG_SPLIT_OFFSET_CAPTURE);
Введение
Метасимволы
Специальные последовательности символов
Модификаторы
Функции
Игорь Борисов http://igor-borisov.ru
Введение
Объявление пространства имен
Иерархия
Правила доступа
Unqualified name
Qualified name
Fully qualified name
Глобальный доступ
Импорт и псевдонимы
Решаемые проблемы
Пересечение имен функций, констант и классов
Использование псевдонимов для удобства использования
Что объявляем?
Классы
Функции
Константы
Разделитель
\
Псевдоконстанта
__NAMESPACE__
<?php
namespace MyProject;
const CONNECT_OK = 1;
class Connection { /* ... */ } function connect() { /* ... */ } ?>
Ошибка
<html>
<?php
namespace MyProject;
<?php
namespace MyProject\Sub\Level;
const CONNECT_OK = 1;
class Connection { /* ... */ } function connect() { /* ... */ } ?>
Не рекомендуется
<?php
namespace MyProject;
const CONNECT_OK = 1;
class Connection { /* ... */ } function connect() { /* ... */ }
namespace AnotherProject;
const CONNECT_OK = 1;
class Connection { /* ... */ } function connect() { /* ... */ }