INSERT INTO sites(host) VALUES('phpjs.org') 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) phpjs.org 网站价值¥460,759(不含域名),MYIP.CN网站综合数据统计 - 域名,Alexa,PR,反向链接,关键字
  测网速 网站优化诊断 广告招商QQ3066631932 CodeForge最好的源码站!   手机测速 测速APP

  
                       

网站页面信息

标题:
描述:
关键字:
sponsored links:
连接:
图片:
网站历史:
sponsored links:

网站流量与估价

网站流量:
网站估价:  (注:不包含域名价值,不代表公司价值)

网站排名

Alexa全球排名:
Google Page Rank:
真假PR鉴别:   (提示:若此处显示网站与查询网站不同,则疑为劫持PR)
Sogou Rank:
百度快照日期:

搜索引擎收录

搜索引擎收录情况反向链接
 谷歌Google:
 百度Baidu:
 微软Bing:
 搜搜Soso:
 雅虎Yahoo:
 有道Youdao:
 搜狗Sogou:

服务器信息

Web服务器:
IP地址:    
IP所在地:

域名注册信息

注册人:
Email:
ICANN注册机构:
创建时间:
修改时间:
过期时间:
状态:
Name Server:
Whois Server:

Alexa 排名走势数据

流量统计: 当日 一周平均 三个月平均
排名:
PV:
日独立IP:

网站在各国/地区的排名

国家/地区访问比例

下属子站点被访问比例

Alexa 排名走势图

Alexa Reach走势图

域名 Whois 记录

Who is phpjs.org at org.whois-servers.net

WHOIS LIMIT EXCEEDED - SEE
WWW.PIR.ORG/WHOIS FOR DETAILS

网站缩略图

sponsored links:

网站访问速度测试

国内Ping速度测试      国内TraceRoute路由测试
美国Ping速度测试      美国TraceRoute路由测试

网站关键字指数 (越高越热门)

域名 phpjs 其他后缀注册情况   查看更多

后缀 注册时间 到期时间 是否注册
.com
.net
.org
.cn
.com.cn
.asia
.mobi

同类相似网站

查看更多
Alexa标题

模拟搜索引擎蜘蛛抓取

Title:php.js - php.js
Description:
Keywords:
Body:
php.js - php.js
HomeFunctionsPackagesCompileAuthorsLicenseWiki / FaqDevelop!
Use PHP functions in JavaScript
php.js
php.js is an open source project that brings high-level PHP functions
to low-level JavaScript platforms such as web browsers, browser extensions (
Mozilla/Firefox,
Chrome
), AIR,
and SSJS
engines like
V8 (
node.js,
v8cgi
), Rhino, and
SpiderMonkey (
CouchDB
)
If you want to perform high-level operations on these platforms,
you probably need to write JS that combines its lower-level functions and
build it up until you have something useful like:
strip_tags(), strtotime(), number_format(), wordwrap().
That's what we are doing for you.
Pure JavaScript so no additional components required.
To use php.js you can either:
Copy-Paste one of our Functions : )
Clone
our Git repo and include the functions you need
Customize a (CommonJS) package.
Come back amp; have it upgraded later on.
Download the
default package (big--use for study only)
PHP is a language with many high-level functions and while they're not
always implemented as consistently as we'd like (mostly to blame on its underlying C parts),
it has a huge following
familiar with its syntax so it makes sense to pick its
API as a reference. Eliminating the need for our own
documentation, thus making life easier, we hope.
We recognize JS - on the other hand - has beautiful language
features, and we encourage you to
learn them.
Never let php.js be an excuse not to.
For the same reason, we're not porting entire language or control structures of PHP;
we stick with the functions.
That said, we think of it as a challenge to port everything and
decided to also port low-level PHP functions like
strpos even
though it may have a JavaScript counterpart
(String.indexOf).
Cause besides the intellectual challenge for us, porting more also
opens up php.js to all kinds of thought excercises
and study purposes.
And so we leave it up to the developer to
decide what to take from
this resource.
And what not.
Featured Functions
date()Date-formatting, just like you know it from PHPbase64_decode()Safe amp; easy data transport, decode messages in JavaScript that were encoded by PHP.
The History of php.js
Kevin van Zonneveld was once working as developer on a project with a lot of client (JS) /
server (PHP) interaction, and found himself coding PHP functions (like base64_decode amp;
urldecode) in JavaScript to smoothen data transport between the two languages.
He stored the stored the functions in a file called php.js which was included in the
project. But even when the project was done, it remained fun trying to port PHP functions
to JavaScript, and so the library grew.
There was a technological challenge in trying to recreate functions such as
date, or sprintf.
Eventually Kevin decided to share the little library on his blog, triggering the enthusiasm
of a lot of developers worldwide. The project was
open sourced in 2008, and many people contributed their own functions in the comments sections
of Kevin's blog.
To try and maintain quality, examples from original PHP documentation were taken and
added as unit tests in the header of each function. These are the same
bits of code you can see under the Example section for any function.
As bugs are reported, more test cases are added to avoid regression.
It was decided that the library deserved a bigger home and a face of its own, and so
the php.js core team (which at that time consisted of Michael White, Felix Geisend ouml;rfer,
Philip Peterson and Kevin) developed the phpjs.org website.
Different core members have come amp; gone but there has always been
a select group pushing
the project forward.
Late 2008
Brett Zamir started
contributing and did't stop. In April 2009 he was responsible for over
245
different PHP functions and has had many ideas considering php.js' future.
Because the library became too big to include at once, and having users copy-paste
functions to their projects proved tedious,
Kevin started working on a
compiler that
allows programmers to select ONLY the functions they need, and wrap them
up in a single customized php.js file.
This took away overhead and even allowed for easy upgrading.
In September 2009 we moved the development of the project to
GitHub.
This opened up a lot of features to help colaboration in development.
Gaining popularity in the
SSJS
world mostly due to
node.js people
needing functions such as html_entity_decode,
we received a lot of requests for a
CommonJS
compatible library and in
April 2010 the compiler took it's first
steps to support it.
And that's where we are now.
We are still trying to port and perfect functions.
Want to help out amp; become a part of our history?
Why not add a comment with new or better code?
It is that easy.
CommentsAdd Comment
NameEmailWebsiteTitleContentUse: strong[CODE]strong
your_stuff('here');
strong[/CODE]strong
for proper code formatting
By submitting code here you are allowing us to use it in php.js hence dual licensing it under the MIT and GPL licensesPaul NormanNov 9th Great library! Bringing a lot of it into TeXWorks (http://code.google.com/p/texworks/) which edits Latex and realated documents and has a QtScirpt (like JavaScript) engine. Really really helpful especially arrays and text handling! Thanks.WoodySep 18th this is very useful ;)aSep 17th aaJoakimAug 13th You guys... Are
F-U-C-K-I-N-G F-A-N-T-A-S-T-I-C!
Thank you VERY much!Zhu HquanAug 9th ha goodjack egwareAug 9th thorn 211jack egwareAug 8th keys of today i nagra2 and 3 keysjack egwareAug 8th i need the keys for thorn 2/3 digi tvhiAug 3rd lt;SCRIPT gt;
function sumDigits(num) {
var i, sum = 0; //
can declare two variables at once
for (i = 1; i lt;= num; i++) {
sum += i; //
add each number to sum (ie, 1 + 2 + ...+
num)
}
// Display result
alert( quot;The sum of the digits from 1
to quot;+ num + quot; is:\n\n\t quot; + sum);
}
lt;/SCRIPT gt; hiAug 3rd
your_stuff('here');
adasdsadAug 2nd
your_stuff('here');
bhupalJul 17th thanks :)
i will no more miss the date() amp; print_r().
keep up the good work!jiduwJul 14th Good.ThanksClaudio de TaunayJul 11th Congratulation ! Great work. Keep walking men ...DavidMar 4th Hello,
Your website is nice but it's a nightmare to access with an IE.
I think there's a solution according to:
http://aralbalkan.com/912
Thanks for your good functions.
Kevin van ZonneveldMar 1st @ Dino B.: Placing it on a CDN would encourage the use of the default package in production. While in fact we are trying to stimulate people to use only the functions they need. Either by compiling, or just copy-pasting some of our functions.
Please never hotlink GitHub's raw sources. As you can achieve the same thing (only without using up their bandwidth) by doing:
$ cd /my/web/app/webroot/js/
$ git clone git://github.com/kvz/phpjs.git
from now, to update phpjs, you can do a:
$ cd /my/web/app/webroot/js/phpjs; git pull;
and to use functions you can include:
/js/phpjs/functions/array/is_array.js
/js/phpjs/functions/datetime/strtotime.js
in your webpages.
Dino B.Feb 23rd Is there a consideration to place this library on a CDN somewhere? Secondly, is hotlinking to the functions (their github locations) encouraged, prohibited, or a gray area?Brett ZamirFeb 20th I added the test files (converted to JavaScript) at http://github.com/kvz/phpjs/tree/master/_workbench/tokenizer/tokenizer_tests/ . Some of them need php.js functions added and there may be some imperfections in the PHP-to-JS conversion process (I corrected some of them that Harmony Framework missed, though it seemed to do a pretty good job). We'll also need to consider the best way to parse the test files, run the JavaScript, and test against the expected results...Brett ZamirFeb 20th @Marco: I'm sorry if I get carried away sometimes; sorry for too much information; I forget who I've talked to about these things. And don't be afraid to ask questions for anything.
Yes, I went back to your constant values; that's good we use the latest.
I agree finishing token_get_all() and testing it is a good idea; I just started the php-to-js code for fun and to test the concept a little.
As far as testing, that is exactly what we can use the quot;phpt quot; files are for. They are test files in the PHP source code. They are written in PHP (though with some blocks indicating what is being tested, what the result is expected to be, etc.) and my idea was to use a PHP-to-JavaScript converter so we could use those tests against all of our functions. These tests for token_get_all can be found in the PHP source code at /ext/tokenizer/tests/ . Again, until we have our own converter, we can try http://www.harmony-framework.com/ for converting those quot;phpt quot; files into JavaScript.Marco MarchiòFeb 20th @Brett: You must clarify me something, remember that i'm new to this project, i've no experience in community work (and related tools such as Github), i'm italian and i speak a medium-level english and right now i'm tired so be patient:).
You talk about quot;.phpt quot; files where can i find them and what do you mean by adapting them to Javascript form?
For the Php parser i think we should finish to fix the token_get_all with lots of tests, improve its performance, create some guidelines about the implementation of the parser and then build it on the token extension.Marco MarchiòFeb 20th @Brett: You are doing a very good work.
I get the constants value from PHP 5.3 so i think that when the function will be released you must change their value according to the last version of PHP.
For the \r\n problem i agree with you to make the \r optional, i forgot that it's present only on Windows.
Right now i'm very busy at work, but when i'll finish (i hope soon) i'll be glad to help you with everything.Brett ZamirFeb 19th @Marco: As I think I may have mentioned before, I have modified your functions to follow our coding standards and also support IE since you cannot do str[3] in IE--string characters can only be accessed by str.charAt(3). (Annoying, but true.)
I believe I also fixed a problem with one of your variables not being declared and thus global.
I also added a HEREDOC test. There was some work to be done with HEREDOC handling but that is now fixed, so again, please apply my changes first before you work on the code again: http://github.com/kvz/phpjs/tree/master/_workbench/tokenizer .
I also renamed token.js to token_get_all.js and renamed what I think used to be quot;test.min.js quot; to a more descriptive quot;file_get_contents.min.js quot;.
As far as \r\n, shouldn't such checks be \r?\n since \r is only Windows? I made the \r optional.
Also, I needed to temporarily add different values for the constants to compare on my system (5.2.6) which uses different numeric values for the constants... What version of PHP are you using? 5.3 or 6? I've kept my own values in the comments but just now reverted to your values since it appears you are using a later edition of PHP.
I also added some additional test files, and supplemented your test with var_export(), but I really think we need to have a greater interaction between PHP and JS to summarize in a line exactly what differed between the PHP version and the JS version (with maybe the PHP producing the value which JS checks against its own).
I'd also really like to adapt all of the quot;.phpt quot; test files in the PHP source to make sure token_get_all.js is parsing PHP perfectly. I think this is a very important function you've made, so I hope we can prove to ourselves and others that this is really robust.
Also, I added a feature to token_get_all.js so that if the user has quot;this.php_js.phpParser quot; defined (though maybe I should make it settable via this.php_js.ini so that people can use ini_set() instead), that object's methods will be called with arguments indicating information about each segment currently being parsed (they'll also need token_name.js in such a case; see http://github.com/kvz/phpjs/tree/master/_experimental/tokenizer ). Although someone can do this with the return results of token_get_all(), it will be faster (and live) to work during the original parsing. And I only need to add a couple of lines of code to get this functionality.
See PHPTokenizer.js for a skeleton object that can be used as the quot;this.php_js.phpParser quot; and see PHPToJS.js for an early beginning at a PHP-to-JavaScript translator which can also be used as an example of such a parser object. We might also get some ideas if not code from the Harmony Framework (at http://www.harmony-framework.com/ ) about how to finish making such a translator.
I am a little busy to work on this now, but would you be interested in adapting the quot;.phpt quot; files into JavaScript form to make sure all of the tests are working? It'd be great to be able to run the tests, and if not showing a diff, at least just summarizing which line is failing and how many lines in the test are failing. Normally for other functions, I think it'd already be ready for release, but I think this one is of the nature that it really should be fully systematically tested first. Then, we can maybe use it to convert other quot;.phpt quot; files into JavaScript! :) Or we could just use Harmony Framework for now, though phpt files also have some non-JS blocks we'd need to parse as well...
Anyhow, some really incredible work, thank you again!!!Marco MarchiòFeb 15th @Brett: Ok let me know if you find some bugBrett ZamirFeb 15th @Marco, I did receive your original email, so no need to send it again. Again, please see http://github.com/kvz/phpjs/raw/master/_workbench/tokenizer/ as I have made modifications of your code there to follow our standards. I'd appreciate it if you could use those versions if you make any further changes. This seems like some extremely impressive work, but I'd like to study it more carefully and maybe compare it to the EBNF out there, etc.Marco MarchiòFeb 15th @Brett: i did not receive your email, if you want to try again i will send you back the test suite that i've builded. Anyway to create this function i haven't looked at any source, i've tested it with a lot of scripts untill i've solved every bug. I've tested the result of the original php function, on a 200kb script, with the one returned by the js function and the result was exactly the same. The only functionality that i haven't tested is the HEREDOC.Marco MarchiòFeb 15th @Brett: i did not receive your email, if you want to try again i will send you back the test suite that i've builded. Anyway to create this function i haven't looked at any source, i've tested it with a lot of scripts untill i've solved every bug. I've tested the result of the original php function (on a 200kb script) with the one returned by the js function and the result was exactly the same. The only functionality that i haven't tested is the HEREDOC.Brett ZamirFeb 15th @Marco: Actually, please see http://github.com/kvz/phpjs/raw/master/_workbench/tokenizer/token_get_all.js for the latest of your function insteadBrett ZamirFeb 15th @Marco: I sent you an email in reply a few days ago. I haven't gotten any reply to it.
FYI, just now I made more changes to bring your token.js (now changed to token_get_all.js and available at http://github.com/kvz/phpjs/raw/fdecb6087c5843e498a63b4e96ae5b6c063e2624/_workbench/tokenizer/token_get_all.js ) more up to our coding standards (see http://wiki.github.com/kvz/phpjs/developerguidelines ) and I also caught a few bugs, now fixed. But I still haven't taken a good look at the code.
Out of curiosity, how did you write this code? Did you look at the C source, use someone's EBNF, or what?
Please see lines 513, 642, 691 for whether those are accidental assignments or not. As maybe the most important coding standard, please don't do inline assignments, as it is unclear whether it is deliberate or not; assign the variable in a separate line.Marco MarchiòFeb 15th @Brett: Have you received my email?Brett ZamirFeb 13th @LEx: Yes, that is a possibility, but there are a couple of reasons we don't take that approach:
1) Adding methods to the built-in object's prototypes can conflict with other libraries or code, adding a kind of omni-global. The problems can occur if other libraries try to add functions of the same name to the prototype, or, more insidiously, cause problems for those iterating over such object (or array, etc.) properties. Yes, when iterating over object properties, the user should always filter out functions or ignore properties which are on the prototype, but many people (and libraries--including many of the functions still in our library) do not do this filtering, either because they don't know about the need for it, or because they don't want to use libraries that intrude in this way. See http://www.jslint.com/lint.html#forin or http://javascript.crockford.com/code.html#for%20statement
2) We also want to make at least one version familiar and easy to PHP developers, though that doesn't prevent us from making other versions like the namespaced version, but it could add some difficulty to maintenance.
One way around this might be to use our own wrappers for things like arrays.
For example, we might change our function array() (different from the built-in JavaScript Array() object) so that when someone does:
var a = array();
they can also use:
a.in_array(...)
Implementing object-style versions that didn't add to the built-in prototypes might work, even though they would require things like strings to also have wrappers created for them, thus not being as convenient, and, even with this, there is still the problem of iterating properties.
And we could have a version for users who didn't care about problems from adding to the native object's prototypes.
Either of these would definitely change the regular PHP API as the input argument would be removed, but other users could still use the regular version if they wished.
One other potential advantage of the wrapper approach would be that other chaining methods could exist, for example, functions that don't return arrays could be combined with those that do into a long chain:
arr.returnArrays().shift(...).map(...).push(...);
As I recall Kevin isn't interested in making such a version part of the regular compiler, but we could host alternative versions if someone is interested in maintaining them or writing code to automate conversions on the server side.LExFeb 12th Why you dont use prototype to inherit and expand native Javascript object like Array, Date or String. It wouldnt be better to use [1,2,3].in_array(1) rather than in_array(1,[1,2,3])? Javascritp is prototype based language. In other hand it can downgrade performance... but still why dont use this approach?Brett ZamirJan 31st @Marco: Sorry for the delayed reply... Have you seen http://www.php.net/manual/en/tokens.php and also the comments there? There's some reference to whitespace as a tokens...Marco MarchiòJan 28th Hi, i'm trying to create the token_get_all function and i need help on a little problem.
Do you know when whitespaces (\t,\n,\r and spaces) are considrered tokens?
The orignal PHP function get only some of them but i can't understand which ones.Brett ZamirJan 27th @cynosure: Hi! Don't mean to be unfriendly, but I imagine Kevin would prefer we limit discussion here to php.js functions. But really quickly, it appears that IE may be (mistakenly) considering the XML Declaration at the beginning of the document as though it were a node (probably considering it a processing instruction which it is not, even though it looks like one)--the declaration info should only be available to the DOM as document.xmlVersion, document.xmlEncoding and document.xmlStandalone , though browser support is unfortunately limited even in Firefox; see http://brettz9.blogspot.com/2009/04/xml-dom-support-test.html ). Thankfully, you can still make cross-browser code here in testing whether the nodeName of a quot;processing instruction quot; is quot;xml quot;; since processing instructions cannot be quot;xml quot;, you would know it is the bogus IE one and can be avoided.
You could confirm IE indeed treats it this way by printing out the nodeType as well; see https://developer.mozilla.org/en/nodeType for the codes. Also, your example is not recursive, as if it were, you would also need to check whether the node were an element and then recurse on its children; currently you are only iterating through the top level nodes. Maybe this was a simplified example...cynosureJan 27th Hi!
I'm working now on an xml parser (not yet on a php type XML API object), but I fount a new funny difference between IE6-8 and any other browsers.
I have a simple XML:
?xml version="1.0" encoding="UTF-8"?
main
response
age6age
response
redirect
redirect
main
When I try to loop the elements in a recursive way, the code above works different in these browsers:
br
xml2Array = function(xml)br
{br
var nodecount = xml.childNodes.length;br
if(nodecount  0)br
{br
var log = '';br
var arr = new Array();br
for(var i=0;inodecount;i++)br
{br
log = log + i + ' - ' + xml.childNodes[i].nodeName + 'br /';br
}br
document.getElementById('foo').innerHTML = log;br
}br
elsebr
{br
var arr = false;br
}br
return arr;br
}br
In IE writes out:
0 - xml
1 - main
In other browsers:
0 - main
Brett Zamir30 Dec '09 Interesting about the delete operator. I knew it didn't work with variables, and imagined it wouldn't work on some built-in objects, but nice to know that formally.
Nice set of examples. It's supposed to get even weirder in IE as far as ordering if you use an object and with properties inherited from the prototype. It's sad that what may be the most usable scripting if not programming language in the world is the least updated. I can live with most of JavaScript's other quirks, even the ease of making accidental globals, but this one should plain and simply just be fixed in the spec and reality.Brett Zamir30 Dec '09 Interesting about the delete operator. I knew it didn't work with variables, and imagined it wouldn't work on some built-in objects, but nice to know that formally.
Nice set of examples. It's supposed to get even weirder in IE as far as ordering if you use an object and with properties inherited from the prototype. It's sad that what may be the most usable scripting if not programming language in the world is the least updated. I can live with most of JavaScript's other quirks, even the ease of making accidental globals, but this one should plain and simply just be fixed in the spec and reality.cynosure29 Dec '09 @Brett Zamir: The delete method have an other issue, it can't remove an element if it have a DontDelete attribute.
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/delete_Operator
In the other hand, associative arrays works in IE6 too, but this is not really an array, this is an object, so .splice won't work in any browsers:
var foobar = new Array();
foobar['x'] = 'a';
foobar['y'] = 'b';
alert(foobar['x'] + ' ' + foobar['y']); // writes "a b"
// and the problems:
alert(foobar.splice('x',1)); // does nothing, writes empty window
alert(foobar.splice(0,1)); // does nothing too
alert(foobar['x'] + ' ' + foobar['y']); // writes "a b" again
// with delete:
delete foobar['x'];
alert(foobar['x'] + ' ' + foobar['y']); // writes "undefined b"
for(var key in foobar) { alert(key); } // writes "y"
// let's test the element orders
foobar['x'] = 'c';
alert(foobar['x'] + ' ' + foobar['y']); // writes "c b", its ok
for(var key in foobar) { alert(key); } // writes "x" and "y" in IE6-8, "y" and "x" in all other browsers
I know, this is exactly what you wrote, I only made a test to everyone who wants to know how it works.Brett Zamir29 Dec '09 @cynosure: Looks like someone else here tried something similar: http://phpjs.org/functions/array_pop:329#comment_354 .
As far as a reference to an array, whatever value you pass in to a function, if it is an array or object, its elements can be acted on by reference and in fact only by reference unless you manually make a copy (though you cannot replace the whole object with something else, or that does make a copy). So, we could adapt your function to work by reference (though still breaking the PHP API which only uses one argument):
function unset(array,index) {
if (typeof array === 'object' amp; amp; typeof array.length == 'number') {
array.splice(index, 1); // Using the delete operator will replace the old value
// with "undefined" in its old slot, but we also want to remove the slot itself,
// so with arrays (in IE too), we can safely use splice().
}
else { // Objects
delete array[index]; // For object properties, this works pretty well, except potentially in IE where
// the property will thankfully no longer be iterated, but it has the annoying feature (for
// the sake of our using objects to imitate PHP associative arrays) that if you later try to
// add back a value with the same property name, it will put your new value in the old
// iteration position. So IE does not truly delete the property, though it may appear that way.
// All other popular browser implementation seem to truly delete the property (and iterate
// in order), at least if it is not an inherited property, but the latest ES spec wasn't able
// to persuade IE to change this behavior
}
}
See the 2nd comment above for the potential problems with this though. Basically in IE, simple objects as associative arrays just won't work perfectly. It is very disappointing. You can get around this by creating an object which wraps your data, but that can get quite ugly. Otherwise, you just have to keep your keys in one array and values in another array.
This is not to speak of our other challenge here of trying to work with only one argument in unset(). JavaScript does not allow us to get the container object or array if we only know the property. Our experimental version of unset() (at http://github.com/kvz/phpjs/blob/master/_experimental/var/unset.js ), allows us to pass in a single argument, but it is a (necessarily) very bad solution as it relies on eval(), and only works on globals passed in as strings. That's a huge compromise just to work with a single argument, so practically speaking, your solution is probably better (though with the above-mentioned caveats).
A similar problem occurs with trying to imitate PHP's extract() and compact(). We don't have a way in JavaScript (unless we exclusively work with globals) to say use the arguments object to obtain or set the local variables of the caller (we can only get access to those variables explicitly passed in as arguments, and only by reference if they are objects or arrays).
I think these may well be the biggest challenges for php.js trying to follow the PHP API. Brett Zamir29 Dec '09 @cynosure: Looks like someone else here tried something similar: http://phpjs.org/functions/array_pop:329#comment_354 .
As far as a reference to an array, whatever value you pass in to a function, if it is an array or object, its elements can be acted on by reference and in fact only by reference unless you manually make a copy (though you cannot replace the whole object with something else, or that does make a copy). So, we could adapt your function to work by reference (though still breaking the PHP API which only uses one argument):
function unset(array,index) {
if (typeof array === 'object' amp; amp; typeof array.length == 'number') {
array.splice(index, 1); // Using the delete operator will replace the old value
// with "undefined" in its old slot, but we also want to remove the slot itself,
// so with arrays (in IE too), we can safely use splice().
}
else { // Objects
delete array[index]; // For object properties, this works pretty well, except potentially in IE where
// the property will thankfully no longer be iterated, but it has the annoying feature (for
// the sake of our using objects to imitate PHP associative arrays) that if you later try to
// add back a value with the same property name, it will put your new value in the old
// iteration position. So IE does not truly delete the property, though it may appear that way.
// All other popular browser implementation seem to truly delete the property (and iterate
// in order), at least if it is not an inherited property, but the latest ES spec wasn't able
// to persuade IE to change this behavior
}
}
See the 2nd comment above for the potential problems with this though. Basically in IE, simple objects as associative arrays just won't work perfectly. It is very disappointing. You can get around this by creating an object which wraps your data, but that can get quite ugly. Otherwise, you just have to keep your keys in one array and values in another array.
This is not to speak of our other challenge here of trying to work with only one argument in unset(). JavaScript does not allow us to get the container object or array if we only know the property. Our experimental version of unset() (at http://github.com/kvz/phpjs/blob/master/_experimental/var/unset.js ), allows us to pass in a single argument, but it is a (necessarily) very bad solution as it relies on eval(), and only works on globals passed in as strings. That's a huge compromise just to work with a single argument, so practically speaking, your solution is probably better (though with the above-mentioned caveats).
A similar problem occurs with trying to imitate PHP's extract() and compact(). We don't have a way in JavaScript (unless we exclusively work with globals) to say use the arguments object to obtain or set the local variables of the caller (we can only get access to those variables explicitly passed in as arguments, and only by reference if they are objects or arrays).
I think these may well be the biggest challenges for php.js trying to follow the PHP API. Brett Zamir29 Dec '09 @cynosure: Looks like someone else here tried something similar: http://phpjs.org/functions/array_pop:329#comment_354 .
As far as a reference to an array, whatever value you pass in to a function, if it is an array or object, its elements can be acted on by reference and in fact only by reference unless you manually make a copy (though you cannot replace the whole object with something else, or that does make a copy). So, we could adapt your function to work by reference (though still breaking the PHP API which only uses one argument):
function unset(array,index) {
if (typeof array === 'object' amp; amp; typeof array.length == 'number') {
array.splice(index, 1); // Using the delete operator will replace the old value
// with "undefined" in its old slot, but we also want to remove the slot itself,
// so with arrays (in IE too), we can safely use splice().
}
else { // Objects
delete array[index]; // For object properties, this works pretty well, except potentially in IE where
// the property will thankfully no longer be iterated, but it has the annoying feature (for
// the sake of our using objects to imitate PHP associative arrays) that if you later try to
// add back a value with the same property name, it will put your new value in the old
// iteration position. So IE does not truly delete the property, though it may appear that way.
// All other popular browser implementation seem to truly delete the property (and iterate
// in order), at least if it is not an inherited property, but the latest ES spec wasn't able
// to persuade IE to change this behavior
}
}
See the 2nd comment above for the potential problems with this though. Basically in IE, simple objects as associative arrays just won't work perfectly. It is very disappointing. You can get around this by creating an object which wraps your data, but that can get quite ugly. Otherwise, you just have to keep your keys in one array and values in another array.
This is not to speak of our other challenge here of trying to work with only one argument in unset(). JavaScript does not allow us to get the container object or array if we only know the property. Our experimental version of unset() (at http://github.com/kvz/phpjs/blob/master/_experimental/var/unset.js ), allows us to pass in a single argument, but it is a (necessarily) very bad solution as it relies on eval(), and only works on globals passed in as strings. That's a huge compromise just to work with a single argument, so practically speaking, your solution is probably better (though with the above-mentioned caveats).
A similar problem occurs with trying to imitate PHP's extract() and compact(). We don't have a way in JavaScript (unless we exclusively work with globals) to say use the arguments object to obtain or set the local variables of the caller (we can only get access to those variables explicitly passed in as arguments, and only by reference if they are objects or arrays).
I think these may well be the biggest challenges for php.js trying to follow the PHP API. Brett Zamir29 Dec '09 @cynosure: Looks like someone else here tried something similar: http://phpjs.org/functions/array_pop:329#comment_354 .
As far as a reference to an array, whatever value you pass in to a function, if it is an array or object, its elements can be acted on by reference and in fact only by reference unless you manually make a copy (though you cannot replace the whole object with something else, or that does make a copy). So, we could adapt your function to work by reference (though still breaking the PHP API which only uses one argument):
function unset(array,index) {
if (typeof array === 'object' amp; amp; typeof array.length !== 'undefined') {
array.splice(index, 1); // Using the delete operator will replace the old value
// with "undefined" in its old slot, but we also want to remove the slot itself,
// so with arrays (in IE too), we can safely use splice().
}
else { // Objects
delete array[index]; // For object properties, this works pretty well, except potentially in IE where
// the property will thankfully no longer be iterated, but it has the annoying feature (for
// the sake of our using objects to imitate PHP associative arrays) that if you later try to
// add back a value with the same property name, it will put your new value in the old
// iteration position. So IE does not truly delete the property, though it may appear that way.
// All other popular browser implementation seem to truly delete the property (and iterate
// in order), at least if it is not an inherited property, but the latest ES spec wasn't able
// to persuade IE to change this behavior
}
}
See the 2nd comment above for the potential problems with this though. Basically in IE, simple objects as associative arrays just won't work perfectly. It is very disappointing. You can get around this by creating an object which wraps your data, but that can get quite ugly. Otherwise, you just have to keep your keys in one array and values in another array.
This is not to speak of our other challenge here of trying to work with only one argument in unset(). JavaScript does not allow us to get the container object or array if we only know the property. Our experimental version of unset() (at http://github.com/kvz/phpjs/blob/master/_experimental/var/unset.js ), allows us to pass in a single argument, but it is a (necessarily) very bad solution as it relies on eval(), and only works on globals passed in as strings. That's a huge compromise just to work with a single argument, so practically speaking, your solution is probably better (though with the above-mentioned caveats).
A similar problem occurs with trying to imitate PHP's extract() and compact(). We don't have a way in JavaScript (unless we exclusively work with globals) to say use the arguments object to obtain or set the local variables of the caller (we can only get access to those variables explicitly passed in as arguments, and only by reference if they are objects or arrays).
I think these may well be the biggest challenges for php.js trying to follow the PHP API.cynosure28 Dec '09 Hi!
In JS can you give a reference to an array in a function call? I need an unset() like function what can cut off an element from an array with a given index ( like unset(foo['bar']; )
My workaround is this:
function unset(array,index)
{
var newarr = new Array();
for(var i in array)
{
if(i != index) newarr[i] = array[i];
}
return newarr;
}
I know this is not the exact way how php's unset works, 'cos it gives only a reference to the array, and handles single variables as well as multiple variables too, but I think this can be usefull for those JS beginners like me, who wants to unset an element from an array. The delete method is buggy for me, or I don't understand how it works well.
Thanks!Brett Zamir23 Dec '09 I misspoke in saying that the case in the switch is superfluous. It will indeed convert quot;\\0 quot; to quot;\u0000 quot; as in PHP. In any case, as I mentioned, you should add an extra '0' to the sequence (and don't add a backslash).Brett Zamir23 Dec '09 @Brant: Sorry, the case in the switch is not superfluous as it will turn quot;\\0 quot; into quot;\u0000 quot; (as does PHP in double or single quotes). In any case, the rest of what I said still applies: don't add a backslash to quot;\u quot;, just add an extra 0 at the end.Brett Zamir23 Dec '09 @Brant: Thanks for letting us know. Fixed in Git. It really should be '\u0000' (was missing a zero), but it won't really make a difference either way because JavaScript already treats quot;\0 quot; as quot;\u0000 quot;. So that case in the switch is superfluous (though I've kept it just to reflect what PHP does). FYI, quot;\u quot; is used to introduce a four-hexadecimal digit sequence in place of a Unicode character--esp. useful if you have to use non-printable characters or non-ASCII characters.Brant Messenger22 Dec '09 IE7 Issue. Search for '\u000' and replace with '\\u000'.Brant Messenger22 Dec '09 In a custom "wscs.namespaced.min.js" package IE7 found an error.
return false;},stripslashes:function(str){return(str+'').replace(/\\(.?)/g,function(s,n1){switch(n1){case'\\':return'\\';case'0':return'\u000';case'':return'';default:return n1;}});},stristr:function(haystack,needle,bool){var pos=0;haystack+='';pos=haystack.toLowerCase().indexOf((needle+'').toLowerCase());if(pos==-1){return false;}else{if(bool){return haystack.substr(0,pos);}else{return haystack.slice(pos);}}},strlen:function(string){var str=string+'';var i=0,chr='',lgth=0;var getWholeChar=function(str,i){var code=str.charCodeAt(i);var next='',prev='';if(0xD800=code code=0xDBFF){if(str.length=(i+1)){throw'High surrogate without following low surrogate';}
Resolution:
br
return false;},stripslashes:function(str){return(str+'').replace(/\\(.?)/g,function(s,n1){switch(n1){case'\\':return'\\';case'0':return'\\u000';case'':return'';default:return n1;}});},stristr:function(haystack,needle,bool){var pos=0;haystack+='';pos=haystack.toLowerCase().indexOf((needle+'').toLowerCase());if(pos==-1){return false;}else{if(bool){return haystack.substr(0,pos);}else{return haystack.slice(pos);}}},strlen:function(string){var str=string+'';var i=0,chr='',lgth=0;var getWholeChar=function(str,i){var code=str.charCodeAt(i);var next='',prev='';if(0xD800=code code=0xDBFF){if(str.length=(i+1)){throw'High surrogate without following low surrogate';}br
Notice the difference '\u000' - '\\u000'Kevin van Zonneveld14 Dec '09 @ cynosure: Yip! Thanks for thinking of us though ; )cynosure3 Dec '09 Sorry, I didn't saw that you found it already ;)
Download
There is a wide variety of packages if the default
doesn't suit you.
You can also compile your own package
to avoid any overhead.
Support us
spread the word:
Use any PHP function in JavaScript
These kind folks have already donated:
Nikita Ekshiyan, Petr Pavel, @HalfWinter, Paulo Freitas, Andros Peña Romo, @andorosu, Raimund Szabo, Nitin Gupta, @nikosdion, Anonymous, Anonymous and Shawn Houser. lt;your name here gt;
RSS
Comments
Functions
Tweets
Kevin
php.js
Brett
Comments
How I can make file_get_contents funcnione in I... Excelente script gracias de Perú. Great library! Bringing a lot of it into TeXWo... Thanks. Great function. @tony: Can you give the sample you are trying t... I tried this function with german umlauts ( #039;ä #039;... this function has a problem with ie8.. it says ...
your_stuff( #039;here #039;);
[/CODE] @Ghabriel: Normally, you can leave comments on ... So, I need to go to somewhere to post my functi... Thanks for this. Just a quickie for those want... @Ghabriel Nunes: Thanks for submitting. If you ... Hi, I did make a preg_replace() function (it ha... @EdorFaus: Good catch (and bad mistake on my pa... I think this code (lines 57-60) is not quite ri... it doesn #039;t work with arrays
http://www.phpguru... The JSLint warning about for quot;for in quot; is quite ... @Brett Zamir: It works now. @Dreamer: Thanks for the report; should be fixe... Bug report: this.urlencode is not a function
R...
hello
[/code]
You didn #039;t mentioned that it #039;s doesn #039;t work cor... @Tom: Thanks for pointing that out... For Chrom... http://jsfiddle.net/kolor/Nt39S/
some browsers... Doesn #039;t work in Chrome 6 You guys are great ! I will place an article ab... I was going to use this code then i saw the eva... please consult this project, that will be helpf... why is the use of print_r functaion in php
i have a problem for use this function on Inter... I was very pleased to find this site. This is a... Nice! Thanks.... @Lazy eyes: Thanks for the input! Fixed in Git.... I #039;ve got a set of keys
[1000000] = gt; 1
[110000... See dependencies My host can not use this fuction
but thanks This entire function can be replaced with the f... This entire function can be replaced with the f... @Kevin: Thanks, I found the problem: It relates... this is very useful ;) aa @e-mike. Thanks for the report. I had just assu... The TypeError mentioned by Dreamer is still the... Compile upgrade to 3.19 error
If you want to d... Hi,
I just want to let you know that I use php... I update the php.js library to the lastest vers... %27Musim+Depan%2C+Barca+Rekrut+Torres+%26amp%3B... @ anton: Please provide the exact url you are p... hey....
I find a bug
Uncaught URIError: URI ... @ Chris: Sorry, if the comment system is lettin... Who uses php.js
Ext for Yii
node.js
ShaniaTwain.com
KillBugs
XSoftware Corporation
TwiPho
mediacode
Sprink
Harmony Framework
If you use php.js, let us know and get linked.
Progress
php.js is complete for 83.2%
php.js on
Stats

数据更新时间

正在更新   

常用工具

桌面软件: MyIP网站信息状态条  WebShot网页快照  SiteMapMaker网站地图生成 
网站信息: Alexa排名查询  PageRank查询/真假PR鉴别/PR劫持检测  外链检查  搜索引擎收录  搜索引擎反向链接  域名注册查询 
网页编辑: 颜色代码选择器  Html特殊符号 
网站调试: 蜘蛛抓取模拟  网站Header信息  网页源代码查看 
代码转换: 火星文查询  繁体/简体转换  Html/js代码转换  Html/UBB代码转换 
友情连接: CodeForge免费源码 CodeForge.com PCFans IT资讯 Ngnix Lighttpd GPhone中国    更多... (PR<5自动转内页)
网站地图: 1 2 3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 250 300 350 400 450 500
免责声明 | 联系我们 | 交换友情链接 | 广告位招商QQ: 1967659002
© 2009 MyIP.cn Dev by MYIP Elapsed:190.731ms 黑ICP备09072263号