Re: Problem replacing part of a string
| From: | Andrey Hristov | Date: | Wed, 29 Aug 2001 15:51:43 +0000 |
| Subject: | Re: Problem replacing part of a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-65038@lists.php.net to get a copy of this message | ||
function txt_change($txt_string) {
$prt_string = str_replace("(", "{", $txt_string);
$prt_string = str_replace(")", "}", $txt_string);
return $prt_string;
}
even you replace with first statement, you "forget" it. Better :
function txt_change($txt_string) {
$txt_string = str_replace("(", "{", $txt_string);
$txt_string = str_replace(")", "}", $txt_string);
return $txt_string;
}
Andrey Hristov
IcyGEN Corporation
http://www.icygen.com
99%
----- Original Message -----
From: "Don" <don@lclcan.com>
To: "php list" <php-general@lists.php.net>
Sent: Wednesday, August 29, 2001 6:48 PM
Subject: [PHP] Problem replacing part of a string
Hi,
I have a PHP routine that writes to a text file. An example output line would be:
fputs($fp, $form["notify_1"] . "\n");
Where $form["notify_1"] is an array of form variables passed to it. What I wish to do is
prior to writing to the text file, I want
to search and replace all ')' with '}' and all '(' with '{'.
I did the following change to the line of code above and wrote the
following function:
fputs($fp, txt_change($form["notify_5"]) . "\n");
function txt_change($txt_string) {
$prt_string = str_replace("(", "{", $txt_string);
$prt_string = str_replace(")", "}", $txt_string);
return $prt_string;
}
My problem is that the search and replace is NOT working. According to the manual, my syntax for
"str_replace" is correct. Does
anyone have an idea?
Thanks,
Don