如何使用 preg_replace 将括号内的逗号替换为冒号
How to replace the comma by colon within the parenthesis using preg_replace
我只想使用 preg_replace
将括号内的逗号 (,) 替换为冒号 (:)
输入:
`parent_id` int(10) unsigned DEFAULT NULL,
`type` enum('text','textarea','mail','uri','date','image','checkbox','menu','menu_option','group','frame','history') NOT NULL DEFAULT 'text',
输出:
`parent_id` int(10) unsigned DEFAULT NULL,
`type` enum('text':'textarea':'mail':'uri':'date':'image':'checkbox':'menu':'menu_option':'group':'frame':'history') NOT NULL DEFAULT 'text',
请推荐我们
使用
echo preg_replace('/\'[\s]*\,[\s]*\'/', "':'", $input);
\'
按字面意思匹配字符 '
[\s]*
将删除单引号和逗号之间的所有空格
试试这个
$a="place your input here";
$b=preg_replace('/\,/', ':', $a);
echo $a."<br/>";
echo $b;
我只想使用 preg_replace
将括号内的逗号 (,) 替换为冒号 (:)输入:
`parent_id` int(10) unsigned DEFAULT NULL,
`type` enum('text','textarea','mail','uri','date','image','checkbox','menu','menu_option','group','frame','history') NOT NULL DEFAULT 'text',
输出:
`parent_id` int(10) unsigned DEFAULT NULL,
`type` enum('text':'textarea':'mail':'uri':'date':'image':'checkbox':'menu':'menu_option':'group':'frame':'history') NOT NULL DEFAULT 'text',
请推荐我们
使用
echo preg_replace('/\'[\s]*\,[\s]*\'/', "':'", $input);
\'
按字面意思匹配字符 '
[\s]*
将删除单引号和逗号之间的所有空格
试试这个
$a="place your input here";
$b=preg_replace('/\,/', ':', $a);
echo $a."<br/>";
echo $b;