duandou2763 2013-04-10 13:07
浏览 26

fgets剥离标签[关闭]

I'm using fgets to read a text file that contains field names delimited with the "<" and ">" characters. It seems like fgets is seeing these field names as tags and stripping them. I thought that only fgetss stripped tags and that fgets should allow this. I'm testing this with the following code:

<?php
$handle = @fopen("Test.txt", "r");
if ($handle) {
    while (($buffer = fgets($handle, 4096)) !== false) {
        echo $buffer;
    }
    if (!feof($handle)) {
        echo "Error: unexpected fgets() fail
";
    }
    fclose($handle);
}
?>

My file is similar to this

filename.txt
Header test
<EOH>
<Field 1>Name<Field 2>Address<Field 3>Country<EOR>
<Field 1>Name<Field 2>Address<Field 3>Country<EOR>

Anyone know how I can retain my field names when reading text from file using fgets or similar. I tried using fgetss and specifying my field names as allowable tags but that didn't work, I guess because they aren't true html tags?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统