PHP该如何将Array数组内容用作替换字串。
$Query=t.WordLIKE:A8eed99b2ANDt.WordLIKE:A4ca4238";$KeywordArray数组Array([A8eed99b2]=>...
$Query = t.Word LIKE :A8eed99b2 AND t.Word LIKE :A4ca4238";
$KeywordArray 数组Array ( [A8eed99b2] => %test15455% [A4ca4238] => %test12334% )
请问PHP该如何将$KeywordArray替换进去$Query 。
输出t.Word LIKE : %test15455% AND t.Word LIKE :%test12334%";
是输出t.Word LIKE : '%test15455%' AND t.Word LIKE :'%test12334%'
少了 ' 符号。 展开
$KeywordArray 数组Array ( [A8eed99b2] => %test15455% [A4ca4238] => %test12334% )
请问PHP该如何将$KeywordArray替换进去$Query 。
输出t.Word LIKE : %test15455% AND t.Word LIKE :%test12334%";
是输出t.Word LIKE : '%test15455%' AND t.Word LIKE :'%test12334%'
少了 ' 符号。 展开
1个回答
展开全部
这个简单
$Query = "t.Word LIKE :A8eed99b2 AND t.Word LIKE :A4ca4238";
$KeywordArray = ["A8eed99b2"=>"%test15455%","A4ca4238"=>"%test12334%"];
foreach ($KeywordArray as $Key=>$Value) {
$Query = str_replace($Key, $Value, $Query);
}
echo $Query;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询