PHPチュートリアル

PHPホーム PHPイントロ PHPインストール PHP構文 PHPコメント PHP変数 PHPエコー/印刷 PHPデータ型 PHP文字列 PHP番号 PHP数学 PHP定数 PHP演算子 PHP If ... Else ... Elseif PHPスイッチ PHPループ PHP関数 PHP配列 PHPスーパーグローバル PHP正規表現

PHPフォーム

PHPフォーム処理 PHPフォームの検証 PHPフォームが必要 PHPフォームのURL / Eメール PHPフォームの完了

PHP Advanced

PHPの日付と時刻 PHPインクルード PHPファイルの処理 PHPファイルのオープン/読み取り PHPファイルの作成/書き込み PHPファイルのアップロード PHPクッキー PHPセッション PHPフィルター PHPフィルターアドバンスト PHPコールバック関数 PHP JSON PHPの例外

PHPOOP _

PHPOOPとは PHPクラス/オブジェクト PHPコンストラクター PHPデストラクタ PHPアクセス修飾子 PHPの継承 PHP定数 PHP抽象クラス PHPインターフェース PHPの特性 PHP静的メソッド PHPの静的プロパティ PHP名前空間 PHPIterables

MySQLデータベース

MySQLデータベース MySQLコネクト MySQL Create DB MySQLテーブルの作成 MySQLの挿入データ MySQLは最後のIDを取得します MySQL Insert Multiple MySQLを準備しました MySQL Select Data MySQL Where MySQL Order By MySQLデータの削除 MySQLアップデートデータ MySQL制限データ

PHP XML

PHPXMLパーサー PHPSimpleXMLパーサー PHPSimpleXML-取得 PHP XMLExpat PHP XML DOM

PHP -AJAX

AJAXイントロ AJAX PHP AJAXデータベース AJAX XML AJAXライブ検索 AJAXポール

PHPの

PHPの例 PHPコンパイラ PHPクイズ PHP演習 PHP証明書

PHPリファレンス

PHPの概要 PHP配列 PHPカレンダー PHPの日付 PHPディレクトリ PHPエラー PHP例外 PHPファイルシステム PHPフィルター PHP FTP PHP JSON PHPキーワード PHP Libxml PHPメール PHP数学 PHPその他 PHP MySQLi PHPネットワーク PHP出力制御 PHP正規表現 PHP SimpleXML PHPストリーム PHP文字列 PHP変数の処理 PHPXMLパーサー PHP Zip PHPタイムゾーン

PHP preg_split()関数

❮PHPRegExpリファレンス

preg_split()を使用して、日付をそのコンポーネントに分割します。

<?php
$date = "1970-01-01 00:00:00";
$pattern = "/[-\s:]/";
$components = preg_split($pattern, $date);
print_r($components);
?>

定義と使用法

このpreg_split()関数は、正規表現の一致を区切り文字として使用して、文字列を配列に分割します。


構文

preg_split(pattern, string, limit, flags)

パラメータ値

Parameter Description
pattern Required. A regular expression determining what to use as a separator
string Required. The string that is being split
limit Optional. Defaults to -1, meaning unlimited. Limits the number of elements that the returned array can have. If the limit is reached before all of the separators have been found, the rest of the string will be put into the last element of the array
flags Optional. These flags provide options to change the returned array:
  • PREG_SPLIT_NO_EMPTY - Empty strings will be removed from the returned array.
  • PREG_SPLIT_DELIM_CAPTURE - If the regular expression contains a group wrapped in parentheses, matches of this group will be included in the returned array.
  • PREG_SPLIT_OFFSET_CAPTURE - Each element in the returned array will be an array with two element, where the first element is the substring and the second element is the position of the first character of the substring in the input string.

技術的な詳細

戻り値: 各項目が正規表現の一致で区切られた入力文字列の一部に対応する部分文字列の配列を返します
PHPバージョン: 4歳以上

その他の例

PREG_SPLIT_DELIM_CAPTUREフラグの使用:

<?php
$date = "1970-01-01 00:00:00";
$pattern = "/([-\s:])/";
$components = preg_split($pattern, $date, -1,
PREG_SPLIT_DELIM_CAPTURE);
print_r($components);
?>

PREG_SPLIT_OFFSET_CAPTUREフラグの使用:

<?php
$date = "1970-01-01";
$pattern = "/-/";
$components = preg_split($pattern, $date, -1,
PREG_SPLIT_OFFSET_CAPTURE);
print_r($components);
?>

❮PHPRegExpリファレンス