简体   繁体   中英

PHP - Keep HTML tags in a text file

My code currently looks something like:

echo "<pre>" include $textfile echo "</pre>";

but the output 'erases' all of the html tags. Is there a way to keep the html tags and have php output exactly how what it says/how it is formatted in the text file?

Thanks!

strip_tags($textfile);

Allow tags:

// Allow <p> and <a>
echo strip_tags($text, '<p><a>');
?>

PHP.net http://php.net/manual/en/function.strip-tags.php

What ever the code you have nothing to do with the stripping of html tags/formatting. Please provide us the complete code you have, so that we may assist you.

不需要回声...。尝试包含

include $textfile;

不知道您的意思是什么,但是您可以尝试执行以下操作:

echo file_get_contents($file);

The problem is how you're trying to use include.

This is the correct syntax.

include("./pathtofile/htmlfile.inc");

The file you include does not have to have any special extension at the end of it so .html will still function properly. If the included text is HTML and has html tags, be sure to not put <?php and ?> tags in that file or else it will parse them as php, which you don't want since there aren't echo statements. You will have the include() call be inside PHP tags in the main program though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM