note 70339 added to function.preg-replace
| From: | elaineseery at hotmail dot com | Date: | Thu, 12 Oct 2006 12:38:31 +0000 |
| Subject: | note 70339 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-118446@lists.php.net to get a copy of this message | ||
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
----
Server IP: 83.138.144.80
Probable Submitter: 217.23.234.66
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/70339
Del: integrated -- https://master.php.net/note/delete/70339/integrated
Del: useless -- https://master.php.net/note/delete/70339/useless
Del: bad code -- https://master.php.net/note/delete/70339/bad+code
Del: spam -- https://master.php.net/note/delete/70339/spam
Del: non-english -- https://master.php.net/note/delete/70339/non-english
Del: in docs -- https://master.php.net/note/delete/70339/in+docs
Del: other reasons-- https://master.php.net/note/delete/70339
Reject -- https://master.php.net/note/reject/70339
Search -- https://master.php.net/manage/user-notes.php