Page 1 of 1

Character replacement

Posted: Thu Aug 12, 2004 5:56 am
by visionmaster
I have a string which eventually has characters I don't want and all of these unallowed characters should be replaced by a pipe |

For example:
", "
" ,"
"| "
" |"
"\""
"\\"

These characters should be replaced by a pipe.

What ist the quickest and most effective way to do that? String fuction or RegExps?

Posted: Thu Aug 12, 2004 6:03 am
by markl999
Probably something like:

Code: Select all

$replace = array(', ', ' ,', '| ', ' |', '\''); //array of stuff to replace
$string = str_replace($replace, '|', $string);