note 42281 modified in function.preg-replace by aidan
| From: | aidan@php.net | Date: | Sun, 22 Aug 2004 13:09:18 +0000 |
| Subject: | note 42281 modified in function.preg-replace by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-75105@lists.php.net to get a copy of this message | ||
[Editors Note:
Actually you have to enclose it in ANY preg delimiter, for example:
@regex@
~regex~
{regex}
#regex#
]
What is not stated in the manual (at least i didn't find it anywhere) is that you have to
enclose the pattern in slashes, so for example this will not work:
<?php
preg_replace("<\/[^>]+>", "\\0\n", $htmlcode);
?>
But this will do the job:
<?php
preg_replace("/<\/[^>]+>/", "\\0\n", $htmlcode);
?>
A primitive example, just to make the point:
<?php
preg_replace("french fries", "freedom fries", $food);
?>
will not do, you have to write:
<?php
preg_replace("/french fries/", "freedom fries", $food);
?>
--was--
What is not stated in the manual (at least i didn't find it anywhere) is that you have to
enclose the pattern in slashes, so for example this will not work:
<?php
preg_replace("<\/[^>]+>", "\\0\n", $htmlcode);
?>
But this will do the job:
<?php
preg_replace("/<\/[^>]+>/", "\\0\n", $htmlcode);
?>
A primitive example, just to make the point:
<?php
preg_replace("french fries", "freedom fries", $food);
?>
will not do, you have to write:
<?php
preg_replace("/french fries/", "freedom fries", $food);
?>
http://php.net/manual/en/function.preg-replace.php