PHP的内置函数内部是如何实现的?
这些函数的编写方式与用户函数相同吗?我的意思是使用 PHP 代码和正则表达式之类的东西?
例如:
filter_var($email, FILTER_VALIDATE_EMAIL);
与
http ://www.totallyphp.co.uk/code/validate_an_email_address_using_regular_expressions.htm
are these functions written the same way as user functions? I mean with PHP code and with regular expressions and stuff like that?
For example:
filter_var($email, FILTER_VALIDATE_EMAIL);
vs.
http://www.totallyphp.co.uk/code/validate_an_email_address_using_regular_expressions.htm
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
PHP 是用 C 编写的。PHP 函数是用高质量的 C 代码编写的,然后编译形成 PHP 语言库,
如果您想扩展 PHP(编辑/编写)自己的函数,请查看:http://www.php.net/~wez/extending-php.pdf
编辑:
给你:
这个是该函数的原始 C 代码:
这是您验证电子邮件的例程:
——这回答了你的问题。 是的,它是由正则表达式内部完成的。
PHP is written in C. The PHP functions are written in high quality C code then compiled to form the PHP langugae library
if you want to extend PHP (edit / write) own functions check this out: http://www.php.net/~wez/extending-php.pdf
EDIT:
here you go :
This is the original C code for the function:
AND HERE IS YOUR VALIDATE EMAIL ROUTINE:
-- this answers your question. Yes, it is done by regex internally.
PHP 函数要么是:
如果你好奇,你可以看一下 PHP 的源代码——这是它的 SVN:http: //svn.php.net/viewvc/
例如,
filter_var()
函数应该定义在 过滤器扩展。PHP functions are either :
If you are curious, you can take a look at the sources of PHP -- here's its SVN : http://svn.php.net/viewvc/
For instance, the
filter_var()
function should be defined somewhere in the sources of the filter extension.没有。 PHP 内部函数是用 C 编写的,而不是 PHP 代码。由于有许多 Zend 运行时宏以及参数如何从 PHP 传输到 C 结构,这看起来相当笨重。
该特定函数确实使用了正则表达式。这也是一个很好的例子:
http://svn.php.net /repository/php/php-src/branches/PHP_5_3/ext/filter/tical_filters.c
在中间的某个位置查找
regexp[]
。Nope. PHP-internal functions are written in C, not with PHP code. Which looks quite unwieldy due to the many Zend-runtime macros and how parameters are transferred from PHP into C structures.
That particular function does use a regular expression. It also makes a nice example:
http://svn.php.net/repository/php/php-src/branches/PHP_5_3/ext/filter/logical_filters.c
Look for
regexp[]
somewhere in the middle.