3v4l.org

run code in 300+ PHP versions simultaneously
<?php // タグの条件 define("PAT_TAG", "(^|[\\s])([##]\\S+)"); // $str1 $str1 = 'タグは #1 #2 です'; echo "$str1\n"; var_dump( extract_tag_arr($str1) ); // -> `1`と`2`が得られる // str2 $str2 = 'タグは #1 #2 です'; echo "$str2\n"; var_dump( extract_tag_arr($str2) ); // -> `1 #2`が得られてしまう $str3 = 'タグは #1\20001#2 です'; echo "$str3\n"; var_dump( extract_tag_arr($str3) ); // -> `1\\20001#2`が得られてしまう // $str からタグ配列を得る function extract_tag_arr($str){ // タグ抽出 $tag_arr = []; preg_match_all('/'.PAT_TAG.'/u' , $str, $ms); foreach ( $ms[0] as $m ) { $tag_arr[] = preg_replace('/(\A[\p{Cc}\p{Cf}\p{Z}]++|[\p{Cc}\p{Cf}\p{Z}]++\z)(#|#)/u', '', $m); } return $tag_arr; }
Output for git.master, git.master_jit, rfc.property-hooks
タグは #1 #2 です array(2) { [0]=> string(1) "1" [1]=> string(1) "2" } タグは #1 #2 です array(2) { [0]=> string(1) "1" [1]=> string(1) "2" } タグは #1\20001#2 です array(1) { [0]=> string(9) "1\20001#2" }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
71.24 ms | 401 KiB | 8 Q