简体   繁体   中英

Php and character for str_replace

actually i have problem for use str_replace , i put my example :

<?php
$chars_1=array('\',"/","&","¬","~","-","_");
$chars_2=array("","","","","","","");

$result=str_replace($chars_1,$chars_2,$text);

?>

The problem it´s when in the array put the character \\ , for the rest i haven´t problem but if i put or use \\ for change by other character i have problem , how i can replace \\ and use in array for replace for nothing in this case , if use this replace with \\ the mini script give me error if no use in replace \\ all ok

Thank´s !

您必须使用双斜杠来转义斜杠:

$chars_1 = array('\\',"/","&","¬","~","-","_");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM