php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #1163 description of ereg_replace() incomplete
Submitted: 1999-02-19 10:26 UTC Modified: 1999-06-21 18:13 UTC
From: achowe at snert dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 3.0.6 OS: Linux
Private report: No CVE-ID: None
 [1999-02-19 10:26 UTC] achowe at snert dot com
I see this as a problem throughout the documentation, but I experienced it
with ereg_replace() :

The return values of ereg_replace() are NOT clearly described. In the case
of success, its evident that the return value is the new string.  However, in
the case of failure to match the pattern, its not specified what the return 
value is (null, empty string, or the original string).

Empirical testing has shown that the original string is returned.

Below is an exmaple that can be used to insert group separators into a number.
The loop termination relies on the fact that, when no further matches are found
the return value is the same as the supplied string parameter.

function groupseparator($num, $delim) {
	for ( ; ; $num = $t) {
		$t = ereg_replace("(.*[0-9])([0-9]{3})", "\\1$delim\\2", $num);
		if ($t == $num)
			break;
	}

	return $num;
}

On a more general note - the documention of functions should be clear to always
indicate what all the possible return values are.  ( I used to edit and read POSIX.1 
and .2 standards, so I kind of got use too more detailed descriptions. ) 


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-06-21 18:13 UTC] jim at cvs dot php dot net
Added a note about the return value of ereg_replace.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 01 01:01:28 2024 UTC