Php 删除之前存在的所有字符_
我的代码是这样的:in('463','267_462'), 我尝试使用preg_replace remove,如果在u($ids=preg_replace('/^[^]*\s*/','',$ids);)之前存在所有字符Php 删除之前存在的所有字符_,php,Php,我的代码是这样的:in('463','267_462'), 我尝试使用preg_replace remove,如果在u($ids=preg_replace('/^[^]*\s*/','',$ids);)之前存在所有字符 我需要这个报税表:在('267'、'463'、'462')我无法得到你需要的报税表。如果需要阵列,可以尝试以下方法: function categoriesIdsFunction($ids){ //I try with preg_replace remove if exi
我需要这个报税表:在('267'、'463'、'462')我无法得到你需要的报税表。如果需要阵列,可以尝试以下方法:
function categoriesIdsFunction($ids){
//I try with preg_replace remove if exists all character before _
$ids = preg_replace('/^[^_]*_\s*/', '', $ids);
$ids = preg_replace('/\s+/', '', $ids);
return "in ('" . str_replace(",","','",$ids) . "') ";
}
$categories_in_article = "267,267_463,267_462";
$categories_in_article_return = categoriesIdsFunction($categories_in_article);
此外,您还可以
内爆(',',$result)
以获得不带符号的字符串。您想要这样的东西吗?
输出:in('267'、'463'、'462')
返回preg\u replace('/\d+\u/','.$id)代码>@Niet the Dark Absol,你是唯一一个明白我要求的人,其他给我减号的人应该学会更仔细地阅读。我给了你一个减号。“这个问题没有显示任何研究成果;它不清楚或没有用处。”@Niet the Dark Absol,它对我非常有用,我错了,你不明白。
$result = array_map(function (string $item) {
return preg_replace('.+_', '', $item);
}, explode(',', $categoriesInArticle));
function test2()
{
$categories_in_article = "267,267_463,267_462";
$stringArray = explode ( "," , $categories_in_article);
$categories_in_article_return = "in (";
foreach($stringArray as $string){
$categories_in_article_return .=
$this->categoriesIdsFunction($string).",";
}
$categories_in_article_return = rtrim($categories_in_article_return,",");
$categories_in_article_return .= ") ";
echo $categories_in_article_return;
}
function categoriesIdsFunction($ids){
//I try with preg_replace remove if exists all character before _
$ids = preg_replace('/^[^_]*_\s*/', '', $ids);
$ids = preg_replace('/\s+/', '', $ids);
return "'".str_replace(",","','",$ids)."'";
}