|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #10596 Suggestions for new functions
Submitted: 2001-05-02 01:16 UTC Modified: 2016-07-01 20:33 UTC
From: pulstar at mail dot com Assigned: cmb (profile)
Status: Wont fix Package: *General Issues
PHP Version: 4.0.4 OS: Windows 98 4.10 english
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2001-05-02 01:16 UTC] pulstar at mail dot com
These are a few suggestions for a new functions. I hope it be useful. Some of them I did myself and it is very useful to me.
1) Parse variables names inside a string with the actual variables in the current scope:

string parse_vars(string $str):

An example:
$str='Width: $specs[0] pixels (the minimum is $min_width)';
$str2="These \$specs[0] and \$min_width are just examples";
echo parse_vars($str);
echo parse_vars($str2);

Will must output:
Width: 250 pixels (the minimum is 300)
These 250 and 300 are just examples
2) Set the PHP internal pointer to point a specific element in an array:

mixed setpos(array $arr, mixed $position):

function setpos(&$arr,$index) {
	if(is_array($arr)) {
		while(list($key,$value)=each($arr)) {
			if($key==$index) {
				return $value;
	return FALSE;
I did this function to get such functionality.
3) Simple Left and Right portions of a string:

function left($str,$length) {
	return substr($str,0,$lenght);

function right($str,$lenght) {
	return substr($str,strlen($str)-$lenght);

PHP have everything to manipulate strings, why do not have these BASIC's string functions too?  :-)
4) A built-in date object

Like the javascript date object, with methods to manipulate dates and time, but capable of manipulate years since 1100 to 9999 as MySQL do.
The methods must be able to convert different date formats (unix timestamps to sql date format and to user readable formats).
5) void include_embed(string url):
Can read a remote file and embed it in the current web page, like the include() function, but translating all links, images and java's to run as they are in the current web page. The translations will do things like this:

In the remote file:
<img scr="image.gif">  
to:  <img src="http://www.remote_address/image.gif">
(The same for forms, java applets, javascripts, Cascade Style Sheets and everything that can be translated).

In the case of the links, they should be:
<a href="file.html">Click me</a>  
to:  <a href="<?=$PHP_SELF?>?embedurl=http://remote_address/file.html">Click me</a>
(this will call a runtime generated php page with an include_embed() on it, which will receive the address from the embedurl variable, and will load the remote file to do the translating again).


Edemilson Lima
PS: the functions names are just suggestions too.  ;-)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-08 06:47 UTC]
re 1):
use eval()

re 2):
this is high-level enough to prevent it from making it a builtin IMO. 

re 3):
* they'd be redundant. substr($string,0,$positive) and substr($string,$negative), e. g. substr($s,0,2) and substr($s,-2) already do what you want.
* PHP is a C descendant. if you want basic-like functions, either use userland functions, or use ASP :)

re 4):
PHP is functional, not OO language. Use a user-defined class.

re 5):
see 2)

as always, you're welcome to write these functions (in C), and propose the diffs for inclusion on php-dev@
 [2016-07-01 20:33 UTC]
-Status: Suspended +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: cmb
 [2016-07-01 20:33 UTC]
> Parse variables names inside a string with the actual variables
> in the current scope

String interpolation is available since a long time.

> Set the PHP internal pointer to point a specific element in an
> array

You could use array_slice() and foreach nowadays.

> Simple Left and Right portions of a string

substr() already offers this functionality.

> A built-in date object

There's DateTime nowadays.

> void include_embed(string url)

Indeed, way to high level and specific.
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Oct 22 18:01:25 2018 UTC