user2734398
user2734398

Reputation: 55

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 !

Upvotes: 1

Views: 55

Answers (1)

Joseph Silber
Joseph Silber

Reputation: 219920

You have to escape the slash, by using a double slash:

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

Upvotes: 1

Related Questions