在php中,将数组中的“\/”替换为“/”
我有一个包含大量\/的数组,因为该数组是从页面的javascript屏幕截图生成的\/应该是/。以下是阵列:在php中,将数组中的“\/”替换为“/”,php,regex,string,Php,Regex,String,我有一个包含大量\/的数组,因为该数组是从页面的javascript屏幕截图生成的\/应该是/。以下是阵列: Array ( [0] => 1 Jet Black [1] => 1B\/350T Black With Copper Tips [2] => 1B\/BGT Black With Burgandy Tips [3] => 1b Natural Black [4] => 2 Darkest Brown
Array (
[0] => 1 Jet Black
[1] => 1B\/350T Black With Copper Tips
[2] => 1B\/BGT Black With Burgandy Tips
[3] => 1b Natural Black
[4] => 2 Darkest Brown
[5] => 4 Chocolate Brown
[6] => 27 Strawberry Blonde
)
我能想到的最好办法是:
$a = array("1B\/BGT Black With Burgandy Tips", "1B\/350T Black With Copper Tips");
foreach ($a as $key => $itsvalue) {
$a[$key] = strreplace("\\\/","\/",$itsvalue)
}
这应该行得通:
$a = array("1B\/BGT Black With Burgandy Tips", "1B\/350T Black With Copper Tips");
foreach ($a as $key => $itsvalue) {
$a[$key] = str_replace("\/","/", $itsvalue);
}
print_r($a);
结果:
代码应为:-
<?php
$a = array("1B\/BGT Black With Burgandy Tips", "1B\/350T Black With Copper Tips");
foreach ($a as $key => $itsvalue) {
$a[$key] = str_replace("\/","/",$itsvalue)
}
?>
希望有帮助。preg\u replace可以为主题获取一个数组,并将为数组中的每个元素运行替换。尝试:
$replacedArray = preg_replace('#\\\/#', '/', $array);
看
$replacedArray = preg_replace('#\\\/#', '/', $array);