使html中的段落包含文件中的文本 [英] making a paragraph in html contain a text from a file

查看:147
本文介绍了使html中的段落包含文件中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个html段落(在div内),我想在其中显示一个简单的固定文本。文本有点长,所以我宁愿文本将在一个单独的txt文件中。

类似于

 < div>< p txt = file.txt>< / p>< / div> 

我可以做类似的事吗?

解决方案

你会想要使用JavaScript或服务器端语言,如PHP,ASP等等。可以用HTML < embed> 标记来完成,这是有道理的,但我没有用过,因为PHP ...等很简单/普通)



Javascript可以工作:下面是一个链接,指向某人在stackoverflow上通过javascript执行类似的操作:如何将一个文本文件的内容加载到一个JavaScript变量中?



PHP(作为服务器端语言的示例)是最简单的方法:

 < div>< p><?php include('myFile.txt'); ?>< / P>< / DIV> 






使用这个(如果您不熟悉PHP),您可以:

1) 检查您的服务器上是否有php。 strong> 2)将您的.html文件的文件扩展名改为.php



3)例如在您新更名的PHP文件


的正文中

I have an html paragraph (inside a div) in which I want to display a simple fixed text. The text is a bit long so I'd rather the text will be in a seperate txt file.
something like

<div><p txt=file.txt></p></div>

Can I do something like that?

解决方案

You'll want to use either JavaScript or a server-side language like PHP, ASP...etc

(supposedly can be done with HTML <embed> tag, which makes sense, but I haven't used, since PHP...etc is so simple/common)

Javascript can work: Here's a link to someone doing something similar via javascript on stackoverflow: How do I load the contents of a text file into a javascript variable?

PHP (as example of server-side language) is the easiest way to go though:

<div><p><?php include('myFile.txt'); ?></p></div>


To use this (if you're unfamiliar with PHP), you can:

1) check if you have php on your server

2) change the file extension of your .html file to .php

3) paste the code from my PHP example somewhere in the body of your newly-renamed PHP file

这篇关于使html中的段落包含文件中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆