dsedug8644 2014-01-31 23:00
浏览 686

我需要将pre标签的滚动条放在内容的行中

I have text files, with thousand of lines, and I want to make a php page where I can see them, and that it opens in the exact line where I want. I mean, the scrollbar must be in the line I want. The file is full open on a pre Tag, but the scroll bar must be in the line 'N'.

This the php to open the file:

 echo "<pre >";
 $file = $pathOfFile;
 $contents = file_get_contents($file);
 $lines = explode("<br>", $contents); // this is your array of words

 foreach($lines as $word)
        echo $word; 

 echo"</pre>";
  • 写回答

1条回答 默认 最新

  • doucheng9634 2014-02-01 00:21
    关注

    My suggestion would be to prepend each entry with an anchor tag:

    echo '<pr>';
    $file = $pathOfFile;
    $contents = $file_get_contents($file);
    $lines = explode('<br>', $contents);
    
    $i = 0;
    foreach($lines as $word)
    {
        echo '<a name="' . $i . '"></a>' . $word . '<br>';
        ++$i;
    }
    
    echo '</pre>';
    

    So your end html would like this:

    <pre>
        <a name="0"></a>Line 1<br>
        <a name="1"></a>Line 2<br>
        <a name="2"></a>Line 3</br>
        ...
        <a name="500"></a>Line 500
    </pre>
    

    Then when you load the page, and want to scroll to a specific tag, use an anchor in the URL. For instance, if you want to go to line 500 of 700, go to:

    http://yoursite.com/somepage.php#500

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器