Replace backslashes with PHP str_replace or regex preg_replace | |||||||||||
How can I replace the backslashes in PHP with functions str_replace or regex preg_replace ? | |||||||||||
| |||||||||||
Hi, To replace backslash for example with forwardslash using str_replace, you have to use double backslash: $value = "\A\B\C"; $updated_value = str_replace("\\", "/", $value); When using regular expression with preg_replace, you can do something like this: $value = "\A\B\C"; $pattern = "/[\\\w]/"; $updated_value = preg_replace($pattern, "/", $value); | |||||||||||
| |||||||||||
| |||||||||||
![]() ![]() ![]() ![]() | |||||||||||
2022 AnswerTabs | Terms | Contact us |