在 PHP 中启用 json_encode

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7318191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:28:30  来源:igfitidea点击:

Enable json_encode in PHP

phpjsoncentosencode

提问by Rob

Could someone advise on how to enable the json_encode function in PHP?

有人可以建议如何在 PHP 中启用 json_encode 功能吗?

I have a clean install of Centos 5.6 and have just installed Virtualmin.

我全新安装了 Centos 5.6 并且刚刚安装了 Virtualmin。

Does anyone know the next steps to take?

有谁知道接下来要采取的步骤?

回答by Fabio

As in http://www.php.net/manual/en/json.requirements.php

http://www.php.net/manual/en/json.requirements.php

Requirements

There is no installation needed to use these functions; they are part of the PHP core.

要求

使用这些功能无需安装;它们是 PHP 核心的一部分。

Just PHP >= 5.2.0

只需PHP >= 5.2.0

Edit: saw in a commentalso this

编辑:在评论中也看到了这个

On RHEL5/CentOS5 add the EPEL repository (http://fedoraproject.org/wiki/EPEL).

After that, installation is as simple as:

在 RHEL5/CentOS5 上添加 EPEL 存储库 ( http://fedoraproject.org/wiki/EPEL)。

之后,安装就像这样简单:

sudo yum install php-pecl-json

Don't know if this apply for your question, I don't have a Centos server...

不知道这是否适用于您的问题,我没有 Centos 服务器...

For Ubuntu:

对于 Ubuntu:

sudo aptitude install php5-json

回答by robguinness

In my case, I came across this question because I was re-compiling PHP will ./configure --disable-alland then individually adding in the extensions I needed. For the case of json_encode(), this is of course included in the JSON extension. To enable this extension, add the option --enable-jsonto your configure command, i.e.:

就我而言,我遇到了这个问题,因为我正在重新编译 PHP will ./configure --disable-all,然后单独添加我需要的扩展。对于 json_encode() 的情况,这当然包含在 JSON 扩展中。要启用此扩展,请将该选项添加--enable-json到您的配置命令中,即:

./configure --disable-all --enable-json ...

./configure --disable-all --enable-json ...

(The "..." refers to the fact that you may have other extensions you may wish to enable.)

(“...”指的是您可能希望启用其他扩展。)

In general, any PHP extension can be enabled either by including the option --with-extnameor --enable-extname(where "extname" is the name of the extension). You can figure out which one of these two syntaxes to use by issuing ./configure --help | grep extname. Of course, you need to have the library itself available and may have to configure the path where it is located (depending on the extension and whether it is in the "default" path).

通常,可以通过包含选项--with-extname--enable-extname(其中“extname”是扩展名)来启用任何 PHP 扩展。您可以通过发出./configure --help | grep extname. 当然,您需要使库本身可用,并且可能必须配置它所在的路径(取决于扩展名以及它是否在“默认”路径中)。

回答by Derek Gogol

On CenotOS and other *nix systems, even if you have PHP compiled with --disable-jsonnot everything may be lost. The first thing of course is to check output from your phpinfo();and search for occurrences of json. If you see json support enabledthen of course you have json extension enabled, but if not, see if you have /etc/php.d/json.inilisted in Additional .ini files parsed. If you do, then this file may look like this:

在 CenotOS 和其他 *nix 系统上,即使您使用--disable-json编译了 PHP,也不会丢失所有内容。当然,第一件事是检查phpinfo(); 的输出并搜索json 的出现。如果您看到启用了 json 支持,那么您当然启用了 json 扩展,但如果没有,请查看已解析的其他 .ini 文件中是否列出了/etc/php.d/json.ini。如果这样做,则此文件可能如下所示:

; Enable json extension module
;extension=json.so

; 启用 json 扩展模块
;extension=json.so

Uncomment the second line and restart your Apache. If Apache started without errors, check your phpinfo()again and see if this enabled your json extension. If if did, you're all set, if not, you may have to find the directory where your php extensions are located and if you see json.soin there, edit the last line to include the full path to that file and restart Apache again. If you don't have json.sofile with your other php extension files, you probably will have to recompile that one extension (you don't need to recompile your whole PHP, but you certainly could, this time with --enable-json), and then try again.

取消注释第二行并重新启动 Apache。如果 Apache 启动没有错误,请再次检查您的phpinfo()并查看是否启用了您的 json 扩展。如果有,则一切就绪,如果没有,则可能需要找到 php 扩展所在的目录,如果在其中看到json.so,请编辑最后一行以包含该文件的完整路径并重新启动又是阿帕奇。如果你的其他 php 扩展文件没有json.so文件,你可能需要重新编译那个扩展(你不需要重新编译整个 PHP,但你当然可以,这次使用 --enable- json),然后再试一次。

Also, if you don't have additional .ini files parsed, you can try adding this extension in your main php.ini, which is usually /etc/php.ini.

此外,如果您没有解析额外的 .ini 文件,您可以尝试在您的主 php.ini(通常是 /etc/php.ini)中添加此扩展名。

回答by d-_-b

For php 7I did this to install json (after hours of struggling):

因为php 7我这样做是为了安装 json(经过数小时的努力):

yum install php70u-json
service nginx restart
service php-fpm restart