English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

$replacewith = "";
$replace = "¬";
$new = str_replace("$replace","$replacewith","$toast");

$replacewith = "";
$replace = "~";
$new = str_replace("$replace","$replacewith","$toast");

The first 3 lines check to see if the variable toast has any "¬" characters in it and them deletes them. The second 3 lines check for this symbol "~" and does the same. I was just wondering if it was possible to put this script all in one str_replace so it replaces all the unwanted characters in one script, instead of doing the str replace function for every single unwanted character.

2007-02-02 01:53:35 · 5 answers · asked by peter s 1 in Computers & Internet Programming & Design

5 answers

The following script removes the lowercase letters b, e, and j
$new=preg_replace("/(b|e|j)/", "" , "aabbccddeeffgghhiijjkk");
echo $new;
?>

output: aaccddffgghhiikk

Basically that line is saying "for the input string aabbccddeeffgghhiijjkk, replace each letter b, e, and j with nothing"

you can add as many as you want..
for instance
(a|b|c|d|e|f|g|h|i|j|k) would erase everything.

2007-02-02 02:22:33 · answer #1 · answered by pzil0cyb3 1 · 0 0

It's possible:

$replacewith = "";
$replace = array("¬", "~");
$new = str_replace($replace, $replacewith, $old);

2007-02-04 19:50:28 · answer #2 · answered by NC 7 · 0 0

I would have thought that this could be a case for using Regular Expressions

2007-02-02 10:03:23 · answer #3 · answered by themaninbushey 1 · 0 0

yes easy,

create an array

$remove_var[] = "¬";
$remove_var[] = "~";

$string = str_replace($remove_var, "", $string);

2007-02-02 11:10:06 · answer #4 · answered by indigo 3 · 0 0

use ereg_replace() instead

2007-02-02 10:02:59 · answer #5 · answered by Moyo 2 · 0 0

fedest.com, questions and answers