如何在PHP中使用逗号从数组中创建单个qoutes列表?
这是我的问题,我有这种类型的字符串如何在PHP中使用逗号从数组中创建单个qoutes列表?,php,arrays,implode,Php,Arrays,Implode,这是我的问题,我有这种类型的字符串 04/19/2017, 04/20/2017, 04/26/2017, 04/28/2017 我想输出如下输出 '04/19/2017','04/20/2017','04/26/2017','04/28/2017' 对于您的特定示例,您可以使用: $result = preg_replace('%([\d/]+)%sim', '"\1"', $string); 输出: "04/19/2017", "04/20/2017", "04/26/2017",
04/19/2017, 04/20/2017, 04/26/2017, 04/28/2017
我想输出如下输出
'04/19/2017','04/20/2017','04/26/2017','04/28/2017'
对于您的特定示例,您可以使用:
$result = preg_replace('%([\d/]+)%sim', '"\1"', $string);
输出:
"04/19/2017", "04/20/2017", "04/26/2017", "04/28/2017"
正则表达式解释:
([\d/]+)
Match the regex below and capture its match into backreference number 1 «([\d/]+)»
Match a single character present in the list below «[\d/]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
A “digit” (any decimal number in any Unicode script) «\d»
The literal character “/” «/»
"\1"
Insert the character “"” literally «"»
Insert the text that was last matched by capturing group number 1 «\1»
Insert the character “"” literally «"»
不使用爆炸和内爆
$string=“2017年4月19日、2017年4月20日、2017年4月26日、2017年4月28日”;
$string=“””。str_替换(“,”,“,”,“,$string)。”代码>查看和。您应该粘贴您的代码,然后添加正则表达式的解释?
([\d/]+)
Match the regex below and capture its match into backreference number 1 «([\d/]+)»
Match a single character present in the list below «[\d/]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
A “digit” (any decimal number in any Unicode script) «\d»
The literal character “/” «/»
"\1"
Insert the character “"” literally «"»
Insert the text that was last matched by capturing group number 1 «\1»
Insert the character “"” literally «"»
<?php
// dates in a string
$data = '04/19/2017, 04/20/2017, 04/26/2017, 04/28/2017';
// break them apart into array elements where the , is
$dates = explode(',', $data);
/* You then have array of dates you can use/display how you want, ie:: */
foreach($dates as $date){
echo $date. '<br/ >';
}
/* OR select single date */
echo $dates[0];