PHP: split()
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php split Test</title> </head> <body> <?php // from https://www.php.net/manual/zh/function.preg-split.php //使用逗号或空格(包含" ", \r, \t, \n, \f)分隔短语 $pattern = '/[\s,:#]+/'; $geovindu="hypertext language, programming geovindu#涂聚文"; $keywords = preg_split("/[\s,:,#]+/", "hypertext language, programming geovindu#涂聚文"); $du="<br/>"; print_r($keywords); echo ($keywords[0].$du); echo ($keywords[1].$du); echo ($keywords[2].$du); echo ($keywords[3].$du); echo ($keywords[4].$du); ?> <?php $search_expression = "apple bear \"Tom Cruise\" or 'Mickey Mouse' another word,涂聚文,GeovinDu"; $words = preg_split("/[\s,]*\\\"([^\\\"]+)\\\"[\s,]*|" . "[\s,]*'([^']+)'[\s,]*|" . "[\s,]+/", $search_expression, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); print_r($words); $geo=' '; if(empty(trim($geo))) { echo ("为空值"); } ?> </body> </html>
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)