PHP 如何构建修复流包装器

发布于 2024-11-17 03:11:49 字数 155 浏览 2 评论 0原文

我需要修复从互联网上动态传入的 XML 文档的部分内容,这意味着我正在使用流,无法等到整个文档加载,因为文件太大而我没有有那么多时间:)所以我考虑使用流包装器,但我有点困惑如何实现它,事实上我没有找到实现 stream_read() 等的线索-方法.... 你能帮我吗?

I need to repair parts of an XML-Document which is coming in from the internet on the fly, mean I'm using a stream an can't wait until the whole document is loaded because the file is too large and I didn't got that much time :) So I thought about using a stream wrapper but I'm kinda stuck how to implement it, in fact I didn't find a clue on implementing the stream_read() and so on -Methods....
Can you help me, please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栖迟 2024-11-24 03:11:49

至于您正在寻找 Stream-Wrapper 类的一些示例代码,请参阅 注册为流包装器的示例类

由于您没有透露太多有关要对流数据应用的修复的性质,因此很难提供更多信息。

也许 流过滤器 是不太复杂的东西,也可以完成这项工作你。根据您的评论,这看起来更合适,因为您不想关心提供流而是使用它。请参阅 stream_filter_register() 的手册页,其中有一个示例关于如何动态过滤流。

由于您尚未分享实际损坏的内容,并且 XML 是一种文件格式,需要完全加载到内存中才能正确处理(严格来说),因此我无法说流过滤器是否确实合适。

严格来说:由于 XML 的性质,您尝试实现的目标在技术上可能是不可能的。

As far as you're looking for some example code for a Stream-Wrapper class, see Example class registered as stream wrapper.

As you have not shared much about the nature of the fixes you want to apply on the streamed data, it's hard to provide more information.

Maybe a stream filter is something less complex which does the job as well for you. And based on your comments this looks more appropriate as you do not want to care about providing the stream but working with it. See the manual page for stream_filter_register() which has an example on how to filter the stream on the fly.

As you have not shared what actually is broken and as XML is a file-format that needs to be fully loaded into memory to deal with it correctly (strictly spoken), I can not say if a stream filter really is appropriate or not.

Strictly spoken: It might not be technically possible what you try to achieve because of the nature of XML.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文