小编Dan*_*Dan的帖子

使用php将HTML输出转换为纯文本

我正在尝试将我的示例HTML输出转换为纯文本,但我不知道如何.我使用file_get_contents,但我尝试转换的页面返回最相似.

$raw = "http://localhost/guestbook/profiles.php";
$file_converted = file_get_contents($raw);
echo $file_converted;
Run Code Online (Sandbox Code Playgroud)

profiles.php

<html>
    <head>
        <title>Profiles - GuestBook</title>
        <link rel="stylesheet" type="text/css" href="css/style.css">
    </head>
<body>
    <!-- Some Divs -->
    <div id="profile-wrapper">
        <h2>Profile</h2>
        <table>
            <tr>
                <td>Name:</td><td> John Dela Cruz</td>
            </tr>
            <tr>
                <td>Age:</td><td>15</td>
            </tr>
            <tr>
                <td>Location:</td><td> SomewhereIn, Asia</td>
            </tr>
        </table>
    </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

基本上,我试图回应这样的事情(纯文本,没有样式)

Profile
Name: John Dela Cruz
Age: 15
Location: SomewhereIn, Asia
Run Code Online (Sandbox Code Playgroud)

但我不知道怎么做.:-(.请帮帮我们,谢谢你们.

编辑:因为我只是在页面内容之后,无论是样式还是纯文本,有没有办法只使用file_get_contents()选择(见下面的代码)?

 <h2>Profile</h2>
        <table>
            <tr>
                <td>Name:</td><td> John Dela Cruz</td>
            </tr>
            <tr>
                <td>Age:</td><td>15</td>
            </tr>
            <tr>
                <td>Location:</td><td> SomewhereIn, Asia</td>
            </tr>
        </table>
Run Code Online (Sandbox Code Playgroud)

html php plaintext

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

html ×1

php ×1

plaintext ×1