如何解决文件写入时屏幕输出显示为"ArrayArray"的问题?
P粉757432491
P粉757432491 2023-08-13 20:03:27
0
1
433
<p>我有一个如下的方法。简化代码以便清晰理解:</p> <pre class="brush:php;toolbar:false;">function somefunction($data){ $somestuff = createMyGeojson($data) write_aa_winter_sports_points_to_file($geojson); return $geojson; } function write_aa_winter_sports_points_to_file($content){ $file = "aa_winter_sports_points.geojson"; $dir = get_template_directory() .'/fs_data/aa_winter_sports_points/override_file_for_upload/'; file_put_contents($dir.$file, $content); }</pre> <p><code>return $geojson</code>将漂亮格式化的json显示在屏幕上,但是当我查看我的文件时,所有相应的数据看起来都是<code>ArrayArray</code>。我尝试了<code>print_r()</code>,但没有帮助。如何使用<code>file_put_contents()</code>将屏幕保存到文件中?</p> <p>这是目前我的文件内容。</p> <p><code>FeatureCollectionaa_winter_sports_pointsArrayArray</code></p>
P粉757432491
P粉757432491

全部回复(1)
P粉714780768

如果你想要一个类似于print_r()输出的字符串格式,可以给函数传递第二个参数true

file_put_contents($dir.$file, print_r($content, true));
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!