note 70339 deleted from function.preg-replace by colder
| From: | colder@php.net | Date: | Thu, 12 Oct 2006 15:28:59 +0000 |
| Subject: | note 70339 deleted from function.preg-replace by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-118461@lists.php.net to get a copy of this message | ||
Note Submitter: elaineseery at hotmail dot com
Reason: in docs
----
another note for newcomers to this function!
you can use variables instead of absolute text when building your input text. however, this
won't work:
$input = "your name" . $_GET['name'];
$in[0] = '/$input/';
$out[0] = "greetings friend!";
$new_contents = preg_replace($in, $out, $contents);
- because the $input is interpreted literally, instead of being expanded.
this will work (note the double quotes around $in[0])
$input = "your name " . $_GET['name'];
$in[0] = "/$input/";
$out[0] = "greetings friend!";
$new_contents = preg_replace($in, $out, $contents);
one more point, if you're using a / in your $input, you'll need to escape it e.g. if you
have
$input = "mysite/stuff/" . $_POST['filename'];
you'll need to change it to
$input = "mysite\/stuff\/" . $_POST['filename'];
note: this is a very simple example, it probably wouldn't take much to break it
and note note: there's a useful tutorial at
http://www.tote-taste.de/X-Project/regex/printable.html