首页 \ 问答 \ 如何使用PHP解析此XML?(How to parse this XML using PHP?)

如何使用PHP解析此XML?(How to parse this XML using PHP?)

我想为网址解析XML: http//www.opencellid.org/cell/get ?key = myapikey&mcc = 250&mc = 99&cellid = 29513&lac = 0

我是PHP的初学者,尝试了如下代码:

$ url =“ http://www.opencellid.org/cell/get?key=myapikey&mcc=250&mnc=99&cellid=29513&lac=0 ”;

$ xml = simplexml_load_file($ url)或die(“feed not loading”);

的print_r($ XML);

后续代码var_dump($ XML);

我想为每个属性做回声,例如lat,lon,range ..对于这个XML url。

我在stackoverflow中发现了许多资源,XML非常标准。 我找不到用于这种XML格式的示例:

任何人都可以给我一个想法? 谢谢。


I would like to do parse XML for the url: http://www.opencellid.org/cell/get?key=myapikey&mcc=250&mnc=99&cellid=29513&lac=0

I am the beginner of PHP and tried the code as below:

$url = "http://www.opencellid.org/cell/get?key=myapikey&mcc=250&mnc=99&cellid=29513&lac=0";

$xml = simplexml_load_file($url) or die("feed not loading");

print_r($xml);

var_dump($xml);

I would like to do echo for each attribute e.g. lat, lon, range.. for this XML url.

I found many resource in stackoverflow which the XML is quite standard. I cannot find an example which is used for this format of XML:

Anyone could give me an idea? Thanks.


原文:https://stackoverflow.com/questions/15611367
更新时间:2021-09-11 09:09

最满意答案

你问:

这个可以吗?

很大程度上,是的。

更准确地说,这取决于您的需求/意图。 如果您需要继续运行以使您的应用程序正常运行(例如,您可能正在转换并保存一些图像),那么您肯定需要一个强大的参考,以便它完成)。

但如果您不需要继续执行,那么您将使用weakSelf模式。 例如,假设您在视图控制器中有一系列调度任务,这些任务仅用于以后触发UI更新。 在这种情况下,如果视图控制器被解除,您可能不需要运行这些块,并且您当然不希望它挂起到视图控制器以获取已被解雇的视图。 (您甚至可能希望在取消视图控制器时取消这些已分派的项目,但这是另一个主题。)

底线,这取决于你的意图。


You ask:

Is this okay?

Largely, yes.

More accurately, it depends upon your needs/intent. If you need this to continue to run for your app to function properly (e.g. maybe you're converting and saving some images), then you definitely want a strong reference so that it finishes).

But if you don't need to continue to execute, then you'd use weakSelf pattern. For example, imagine you had a series of dispatched tasks in a view controller that were there solely to later trigger UI updates. In that case, if the view controller was dismissed, you might not need these blocks to run, and you certainly wouldn't want it to hang on to the view controller for a view that was long since dismissed. (You might even want to cancel those dispatched items when the view controller was dismissed, but that's another topic.)

Bottom line, it depends upon your intent.

相关问答

更多
  • 内存管理并没有什么不同,因为您使用的是异步回调。 myArchive应该是您正在执行此操作的任何类的属性。您希望它坚持到任务完成为止,对吗? @property (retain) MyClass *myArchive; 然后.. myArchive = [[MyClass alloc] init]; void (^on_success_callback)(void) = ^(void){ NSLog(@"success"); self.myArchive = nil; }; 您需要确保 ...
  • 你问: 这个可以吗? 很大程度上,是的。 更准确地说,这取决于您的需求/意图。 如果您需要继续运行以使您的应用程序正常运行(例如,您可能正在转换并保存一些图像),那么您肯定需要一个强大的参考,以便它完成)。 但如果您不需要继续执行,那么您将使用weakSelf模式。 例如,假设您在视图控制器中有一系列调度任务,这些任务仅用于以后触发UI更新。 在这种情况下,如果视图控制器被解除,您可能不需要运行这些块,并且您当然不希望它挂起到视图控制器以获取已被解雇的视图。 (您甚至可能希望在取消视图控制器时取消这些已分派 ...
  • 不是你问的问题的直接答案,而是...... 如何保留可重用节点池? 不是在死亡时移除节点,而是将其hidden属性设置为true并将其添加到重用队列。 首先尝试使现有节点出列,而不是始终创建新节点。 I've figured out how to stop the retain cycles. I had to give the action a key so then instead of removing all actions I'm only removing the action for key. ...
  • getCombineIdAndNames非常好。 您正在alloc字典并在返回之前自动释放它。 没错。 这会告诉我内存泄漏是由gObjAppDelegatePtr实例引起的。 要么是它没有释放它的财产,要么整个物体都被泄露了。 另外,在getCombineIdAndNames可以改进的一件事是使用NSMutableDictionary的便捷构造函数来完全避免所有的alloc / release调用。 您还可以使用新的Obj-C容器语法: -(NSMutableDictionary *)getCombineI ...
  • 你是如何从你的各种视图控制器上退出的? 我注意到你提到,当游戏结束时,你将另一个VC推入堆栈,但我认为这个VC链将在某个时候放松回到你的初始菜单? (实际上,我想知道你是否只是在循环,因此每次玩游戏时都会增加新的VC。) 要创建一个un-wind segue,只需在目标 VC(即:主菜单)中创建一个空方法,如下所示: - (IBAction)unwindToMainMenu:(UIStoryboardSegue*)sender { // Intentional NOP } (注意:确保它也列在标题 ...
  • 每次更改方向时,Android都会创建并启动新活动。 内存泄漏是由于垃圾收集器无法收集不再需要的旧活动,因为单独的线程仍在运行,并且 - 作为内部类 - 正在保留活动。 要消除内存泄漏,您需要在销毁活动时停止并结束单独的线程。 boolean stopThread; private void updateTimerAndSeekBar() { stopThread = false; Thread updater = new Thread() { ... ...
  • 不,您不需要在onDestroy中将位图设置为null。 特别是如果您正在使用来自资源的图像,那么无论如何都会在Resources中保留这些参考。 你可能想要考虑的是使用StateDrawable并改变状态而不是一直切换drawable ,只是为了你自己的理智。 但是这种用法不应该导致OOM,除非你有很多图像或其他问题。 No, you do not need to set bitmaps to null in onDestroy. Especially not if you're using images ...
  • SecItemCopyMatching将属性复制到attrResult 由于您有副本,因此您有责任在某些时候发布它: CFRelease(attrResult) “ 核心基础内存管理指南”中对此进行了描述 SecItemCopyMatching copies an attribute into attrResult Since you have a copy, you are responsible for releasing it at some point with: CFRelease(attrRe ...
  • 否 - weakObserver会weak ,所以如果observer被释放,它将自动nil ,但是如果addObserver:...保留观察者,那么它将保留观察者。 对象中没有关于先前引用所持有的方式的历史,它是控制自己行为的引用本身。 但是, NSNotificationCenter不保留观察者,观察者几乎从不保留通知中心。 没有保留周期。 你所引用的文字或多或少都是这样说的:存储在通知中心内的指针将变得悬而未决,即它没有断言所有权。 你所做的也不会使存储在中心内的引用自动nil 。 从iOS 9和OS ...
  • 就像我在你上一篇文章中所说,细节很重要。 非MFC dll在MFC dll之前加载,如果在MFC退出之前没有释放任何数据,MFC会错误地将此报告为内存泄漏。 这是一个已知问题 ,当使用opencv和mfc时会出现问题。 解决方案是: 静态链接MFC库(最常见的方式) 尝试解决方法强制首先在上面的链接中加载mfc dll 如本问题所示延迟加载dll。 Like I said in your last post, the details are important. The non-MFC dll loads ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)