php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #68632 Bad practice preg_quote() example
Submitted: 2014-12-19 23:15 UTC Modified: 2014-12-19 23:23 UTC
From: mfischer@php.net Assigned: aharvey (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
3 + 29 = ?
Subscribe to this entry?

 
 [2014-12-19 23:15 UTC] mfischer@php.net
Description:
------------
http://php.net/manual/en/function.preg-quote.php

The preg_quote() example is a bad practice:

$textbody = "This book is *very* difficult to find.";
$word = "*very*";
$textbody = preg_replace ("/" . preg_quote($word) . "/",
                          "<i>" . $word . "</i>",
                          $textbody);


If the text would contain a '/' this would easily break and thus the example should include the delimiter, i.e.

preg_quote($word, "/")


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-12-19 23:23 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=335316
Log: Include delimiter in preg_quote() example.

Fixes doc bug #68632 (Bad practice preg_quote() example).
 [2014-12-19 23:23 UTC] aharvey@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: aharvey
 [2014-12-19 23:23 UTC] aharvey@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.

Great catch!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 10:01:32 2024 UTC