<!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>
标签:PHP,echo,split,keywords,du,php From: https://www.cnblogs.com/geovindu/p/17376939.html