使用 php 将 post 数组转换为单引号
convert post array to single quote using php
我在数组中有这种形式 post:
array([tags] => test,test1,test2,test3,test4);
我需要用单引号 '
打印每个标签并用 ,
分隔,如下所示:
'test','test1','test2','test3','test4'
如何创建和打印此输出?!
$tags = explode(',', $array['tags']);
echo implode(',', array_map(function($tag) { return "'$tag'"; }, $tags));
$tags = explode(',', $array['tags']);
$quoted_tags = array_map(function($x) { return "'$x'"; }, $tags);
$string = implode(',', $quoted_tags);
如果您要将其存储在数据库中,请不要忘记对标签进行转义。
$newtags="'".str_replace(",","','",$array['tags'])."'";
我在数组中有这种形式 post:
array([tags] => test,test1,test2,test3,test4);
我需要用单引号 '
打印每个标签并用 ,
分隔,如下所示:
'test','test1','test2','test3','test4'
如何创建和打印此输出?!
$tags = explode(',', $array['tags']);
echo implode(',', array_map(function($tag) { return "'$tag'"; }, $tags));
$tags = explode(',', $array['tags']);
$quoted_tags = array_map(function($x) { return "'$x'"; }, $tags);
$string = implode(',', $quoted_tags);
如果您要将其存储在数据库中,请不要忘记对标签进行转义。
$newtags="'".str_replace(",","','",$array['tags'])."'";