Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中,将数组中的“\/”替换为“/”_Php_Regex_String - Fatal编程技术网

在php中,将数组中的“\/”替换为“/”

在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

我有一个包含大量\/的数组,因为该数组是从页面的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 
    [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);