php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #50232 preg_replace - pattern description omits mention of string delimiter
Submitted: 2009-11-19 15:56 UTC Modified: 2010-01-12 02:58 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: simonokewode at hotmail dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: n/a
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: simonokewode at hotmail dot com
New email:
PHP Version: OS:

 

 [2009-11-19 15:56 UTC] simonokewode at hotmail dot com
Description:
------------
Users moving from ereg_replace to preg_replace will not know that delimiters are required unless already familiar w/ regex. Huge numbers of newbies will need to do this.
This entry does not need to explain how to use them, but should mention that they are required, and there should be an explanation of regex delimiters somewhere in the manual since they are critical for basic functionality.

The preg_quote entry mentions delimiters, and may be a good reference link from the preg_replace pattern description.

A very simple example of preg_replace in the function list would highlight the existence and use of delimiters; then the complex examples will be easier to understand.
preg_replace('/text/', 'new text', $string)

Reproduce code:
---------------
---
From manual page: function.preg-replace
---
Parameters

pattern

    The pattern to search for. It can be either a string or an array with strings.

    The e modifier makes preg_replace() treat the replacement parameter as PHP code after the appropriate references substitution is done. Tip: make sure that replacement constitutes a valid PHP code string, otherwise PHP will complain about a parse error at the line containing preg_replace().


Expected result:
----------------
Parameters

pattern

    The pattern to search for. It can be either a string or an array with strings. Use regex delimiters on strings [link to preg_quote() or regex ref].

    The e modifier makes preg_replace() treat the replacement parameter as PHP code after the appropriate references substitution is done. Tip: make sure that replacement constitutes a valid PHP code string, otherwise PHP will complain about a parse error at the line containing preg_replace().



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-24 19:48 UTC] daniel dot egeberg at gmail dot com
It already says that delimiters are needed around the pattern here: http://php.net/manual/en/intro.pcre.php
 [2009-11-24 20:38 UTC] simonokewode at hotmail dot com
Well that's good to know. So someone needing to move from ereg_replace to this function is expected to know that they should read the "Regular Expressions (Perl-Compatible)" description first?
A note to that effect would help the many people who will be coming straight here for a single purpose. If PHP is eliminating a function, I think it is right to make it straightforward to convert.
 [2009-12-03 06:43 UTC] traveltechrcs at yahoo dot com
I am new to php and found this issue after and install of an opensource search script install. I did many searches and this is one of the resources I found. The other resources provided no clear cut resolutions as examples for using preg_replace syntax with delimiters. I also found that many support folks are directing their users to include a line of code to simply turn of the error reporting. I'm not sure what kind of problems this will cause down the road but it doesn't seem like a good idea to me. Other resources are directing users to use the mb_eregi_replace as a solution. As a noobie as put in your comments I think we could use a clear, real life example and direction as far as error reporting and the use of mb_eregi_replace. Here is a line of my code that was converted to use mb_eregi_replace. 
$a = mb_eregi_replace($char[0], $char[1], $a);
It would help to see an example of a conversion from that to preg_replace.

Thanks
Tsalagi
 [2009-12-19 21:10 UTC] svn@php.net
Automatic comment from SVN on behalf of degeberg
Revision: http://svn.php.net/viewvc/?view=revision&revision=292344
Log: Closes #50232.
 [2009-12-19 21:11 UTC] degeberg@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

I've added an additional section that elaborates on the delimiters.
 [2010-01-12 02:58 UTC] simonokewode at hotmail dot com
Thanks for improving the documentation of delimiters - it's a good overview description. It's too bad the original problem, no mention of the existence of delimiters in the function pattern description, was determined to be unworthy of addressing even by a word or two.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 15:01:31 2024 UTC