为什么我在浏览器中看不到文件的内容?

时间:2018-01-18 17:05:28

标签: php

<?php 

$content=file("xml.txt");
echo '<pre><code>';
foreach($content as $val){
   echo $val;
 }
echo '</code></pre>';
?>

这是我试图通过该PHP代码阅读的文本文件。此代码与文本一起正常工作,但遗憾的是没有阅读代码。 下面的代码是xml.txt文件。

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="softs.hh.androidpermissions.MainActivity">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

1 个答案:

答案 0 :(得分:0)

尝试用htmlentities包装行:

$content=file("xml.txt");
echo '<pre><code>';
foreach($content as $val){
    echo htmlentities($val);
}
echo '</code></pre>';
相关问题