php从文件中解析ascii文本获取内容
大家早上好,我有一个新问题: 我试图将来自 SIMBAD 数据库查询的一组数据保存到 mysql 中(它是一个恒星对象数据库)。 如果您在浏览器中输入以下网址: http://simbad.u-strasbg.fr/simbad/sim-id?output.format=ASCII&Ident=hd%201&OutputMode=VOTable 你会得到一个用单独的行格式化的结果,但是如果你使用
<?php
$cadaart = 'http://simbad.u-strasbg.fr/simbad/sim-id?output.format=ASCII&Ident=hd%201';
$handler = curl_init($cadaart);
$response = curl_exec ($handler);
curl_close($handler);
echo $response;
?>
或一个简单的 file_get_content 并回显响应,你会得到包含所有信息的一行,这使我无法解析...关于如何解决这个问题有什么想法吗?
谢谢。
Good morning all, i have a new question:
I'm trying to save into mysql a set of data coming from a SIMBAD database query (it's a stellar objects dataabse).
If you enter this url into the browser: http://simbad.u-strasbg.fr/simbad/sim-id?output.format=ASCII&Ident=hd%201&OutputMode=VOTable
you get a result formated with separate lines, but if you use
<?php
$cadaart = 'http://simbad.u-strasbg.fr/simbad/sim-id?output.format=ASCII&Ident=hd%201';
$handler = curl_init($cadaart);
$response = curl_exec ($handler);
curl_close($handler);
echo $response;
?>
or a simple file_get_content and echo the response you get a single line with all information, which makes me impossible to parse... Any idea on how to solve this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
字符串已经换行,
您可以使用 file 将该 URL 中的内容转换为数组(每行是数组元素)
The string is already with line-break,
you can use file to convert contents from that URL into an array (each line is an array element)
这可能只是 LF 和 CRLF 之间的区别。 URL 的输出是 LF,在您查看它的位置(浏览器?),它可能不会被解析为新行。
尝试
$response = str_replace("\n", "\r\n", $response);
看看这是否有任何区别It's probably just the difference between an LF and a CRLF. The output from your URL is LF, which, in where you're viewing it (browser?), is probably not parsed as a new line.
Try
$response = str_replace("\n", "\r\n", $response);
and see if this makes any difference