http://202.103.244.125/catst.php
如上,刚接触PHP被这弄得好焦灼!json_decode出来的永远都是null啊!!!网上的方法也都试了,求大神帮忙
回复讨论(解决方案)
我就不相信你都试了
$url = 'http://202.103.244.125/catst.php';$s = file_get_contents($url);print_r(json_decode(substr($s, 3)));
Array( [0] => stdClass Object ( [menutype] => A [groupx] => 0 [titleng] => 凉菜 [titlech] => Cold Dish ) [1] => stdClass Object ( [menutype] => A [groupx] => 1 [titleng] => 汤 粥 [titlech] => Soup Porrdg ) [2] => stdClass Object ( [menutype] => A [groupx] => 2 [titleng] => 烫菜 [titlech] => Hot food ) [3] => stdClass Object ( [menutype] => A [groupx] => 3 [titleng] => 素菜 [titlech] => Veget -able ) [4] => stdClass Object ( [menutype] => A [groupx] => 4 [titleng] => 主食 [titlech] => Main Food ) [5] => stdClass Object ( [menutype] => A [groupx] => 5 [titleng] => 烤鱼 啤酒鱼 [titlech] => 烤鱼 啤酒鱼 ) [6] => stdClass Object ( [menutype] => A [groupx] => 6 [titleng] => 干锅 汤锅 [titlech] => Gangou Hotpot ) [7] => stdClass Object ( [menutype] => A [groupx] => 7 [titleng] => 铁板 煲仔 [titlech] => Sheet Hotpot ) [8] => stdClass Object ( [menutype] => A [groupx] => 8 [titleng] => 砂锅 [titlech] => Sha Guo ) [9] => stdClass Object ( [menutype] => A [groupx] => 9 [titleng] => [titlech] => ) [10] => stdClass Object ( [menutype] => A [groupx] => 10 [titleng] => 特别 推荐 [titlech] => Special Food ) [11] => stdClass Object ( [menutype] => A [groupx] => 11 [titleng] => 十八酿 [titlech] => 十八酿 ) [12] => stdClass Object ( [menutype] => A [groupx] => 12 [titleng] => 饮料 茶 [titlech] => Drink Tea ) [13] => stdClass Object ( [menutype] => A [groupx] => 13 [titleng] => 其他 自定义 [titlech] => 其他 自定义 ) [14] => stdClass Object ( [menutype] => A [groupx] => 14 [titleng] => 白酒 啤酒 [titlech] => Wine Beer ))
弄个 BOM 头害自己
http://202.103.244.125/catst.php
如上,刚接触PHP被这弄得好焦灼!json_decode出来的永远都是null啊!!!网上的方法也都试了,求大神帮忙
正解
我就不相信你都试了
$url = 'http://202.103.244.125/catst.php';$s = file_get_contents($url);print_r(json_decode(substr($s, 3)));
Array( [0] => stdClass Object ( [menutype] => A [groupx] => 0 [titleng] => 凉菜 [titlech] => Cold Dish ) [1] => stdClass Object ( [menutype] => A [groupx] => 1 [titleng] => 汤 粥 [titlech] => Soup Porrdg ) [2] => stdClass Object ( [menutype] => A [groupx] => 2 [titleng] => 烫菜 [titlech] => Hot food ) [3] => stdClass Object ( [menutype] => A [groupx] => 3 [titleng] => 素菜 [titlech] => Veget -able ) [4] => stdClass Object ( [menutype] => A [groupx] => 4 [titleng] => 主食 [titlech] => Main Food ) [5] => stdClass Object ( [menutype] => A [groupx] => 5 [titleng] => 烤鱼 啤酒鱼 [titlech] => 烤鱼 啤酒鱼 ) [6] => stdClass Object ( [menutype] => A [groupx] => 6 [titleng] => 干锅 汤锅 [titlech] => Gangou Hotpot ) [7] => stdClass Object ( [menutype] => A [groupx] => 7 [titleng] => 铁板 煲仔 [titlech] => Sheet Hotpot ) [8] => stdClass Object ( [menutype] => A [groupx] => 8 [titleng] => 砂锅 [titlech] => Sha Guo ) [9] => stdClass Object ( [menutype] => A [groupx] => 9 [titleng] => [titlech] => ) [10] => stdClass Object ( [menutype] => A [groupx] => 10 [titleng] => 特别 推荐 [titlech] => Special Food ) [11] => stdClass Object ( [menutype] => A [groupx] => 11 [titleng] => 十八酿 [titlech] => 十八酿 ) [12] => stdClass Object ( [menutype] => A [groupx] => 12 [titleng] => 饮料 茶 [titlech] => Drink Tea ) [13] => stdClass Object ( [menutype] => A [groupx] => 13 [titleng] => 其他 自定义 [titlech] => 其他 自定义 ) [14] => stdClass Object ( [menutype] => A [groupx] => 14 [titleng] => 白酒 啤酒 [titlech] => Wine Beer ))好像真的行了!!!
请问那个substr()的参数为什么是3啊?如果处理其他的json文件也是3吗?还是需要做个判定呢?
utf-8 的BOM 头,是三个字符,所以用 substr 跳过前 3 个字符
既然是要输出 json 那么程序文件要保存为 utf-8 无 BOM 格式
多谢版主!!

PHPSession失效的原因包括配置错误、Cookie问题和Session过期。1.配置错误:检查并设置正确的session.save_path。2.Cookie问题:确保Cookie设置正确。3.Session过期:调整session.gc_maxlifetime值以延长会话时间。

在PHP中调试会话问题的方法包括:1.检查会话是否正确启动;2.验证会话ID的传递;3.检查会话数据的存储和读取;4.查看服务器配置。通过输出会话ID和数据、查看会话文件内容等方法,可以有效诊断和解决会话相关的问题。

多次调用session_start()会导致警告信息和可能的数据覆盖。1)PHP会发出警告,提示session已启动。2)可能导致session数据意外覆盖。3)使用session_status()检查session状态,避免重复调用。

在PHP中配置会话生命周期可以通过设置session.gc_maxlifetime和session.cookie_lifetime来实现。1)session.gc_maxlifetime控制服务器端会话数据的存活时间,2)session.cookie_lifetime控制客户端cookie的生命周期,设置为0时cookie在浏览器关闭时过期。

使用数据库存储会话的主要优势包括持久性、可扩展性和安全性。1.持久性:即使服务器重启,会话数据也能保持不变。2.可扩展性:适用于分布式系统,确保会话数据在多服务器间同步。3.安全性:数据库提供加密存储,保护敏感信息。

在PHP中实现自定义会话处理可以通过实现SessionHandlerInterface接口来完成。具体步骤包括:1)创建实现SessionHandlerInterface的类,如CustomSessionHandler;2)重写接口中的方法(如open,close,read,write,destroy,gc)来定义会话数据的生命周期和存储方式;3)在PHP脚本中注册自定义会话处理器并启动会话。这样可以将数据存储在MySQL、Redis等介质中,提升性能、安全性和可扩展性。

SessionID是网络应用程序中用来跟踪用户会话状态的机制。1.它是一个随机生成的字符串,用于在用户与服务器之间的多次交互中保持用户的身份信息。2.服务器生成并通过cookie或URL参数发送给客户端,帮助在用户的多次请求中识别和关联这些请求。3.生成通常使用随机算法保证唯一性和不可预测性。4.在实际开发中,可以使用内存数据库如Redis来存储session数据,提升性能和安全性。

在无状态环境如API中管理会话可以通过使用JWT或cookies来实现。1.JWT适合无状态和可扩展性,但大数据时体积大。2.Cookies更传统且易实现,但需谨慎配置以确保安全性。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

SublimeText3 Linux新版
SublimeText3 Linux最新版

记事本++7.3.1
好用且免费的代码编辑器

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中