Req #10596 [Sus->Wfx]: Suggestions for new functions
| From: | cmb@php.net | Date: | Fri, 01 Jul 2016 20:33:09 +0000 |
| Subject: | Req #10596 [Sus->Wfx]: Suggestions for new functions | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-201976@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=10596&edit=1
ID: 10596
Updated by: cmb@php.net
Reported by: pulstar at mail dot com
Summary: Suggestions for new functions
-Status: Suspended
+Status: Wont fix
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
Operating System: Windows 98 4.10 english
PHP Version: 4.0.4
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> 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.
Previous Comments:
------------------------------------------------------------------------
[2001-06-08 06:47:02] cynic@php.net
re 1):
use eval()
re 2):
this is high-level enough to prevent it from making it a builtin IMO.
re 3):
Because
* 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@
------------------------------------------------------------------------
[2001-05-02 01:16:47] 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";
$specs[0]=250;
$min_width=300;
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)) {
reset($arr);
while(list($key,$value)=each($arr)) {
if($key==$index) {
if(!prev($str))
end($str);
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).
Regards,
Edemilson Lima
PS: the functions names are just suggestions too. ;-)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=10596&edit=1