2011-12-15 02:45
采纳率: 0%
浏览 49


I'm building a super simple PHP CMS, and have a question about formatting text...

I'm storing my news files in .txt files (should be SQL, I know), and would like to know how to format the text that gets saved in the text file. This is the code that stores the lines that I want to format:

$newsTitle = isset($_POST["title"]) ? $_POST["title"] : "Untitled";
$submitDate = date("m/d/y g:iA");

I want to wrap the first line in an <h2> and the second line in an <h3>, but I have no idea how. I tried just wrapping the m/d/y g:iA bit in the second line with a <h3> but that generated some really weird code in the .txt file.


图片转代码服务由CSDN问答提供 功能建议

我正在构建一个超级简单的PHP CMS,并且对格式化文本有疑问......

我将我的新闻文件存储在.txt文件中(应该是SQL,我知道),并且想知道如何格式化保存在文本文件中的文本。 这是存储我要格式化的行的代码:

  $ newsTitle = isset($ _ POST [“title”])?  $ _POST [“title”]:“Untitled”; 
 $ submitDate = date(“m / d / yg:iA”); 

我想要 将第一行包装在&lt; h2&gt; 中,将第二行包装在&lt; h3&gt; 中,但我不知道如何。 我尝试用&lt; h3&gt; 包装第二行中的 m / d / y g:iA 位,但这会在.txt文件中生成一些非常奇怪的代码。


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doucai9270 2011-12-15 02:52
    $newsTitle = isset($_POST["title"]) ? $_POST["title"] : "Untitled";
    $submitDate = date("m/d/y g:iA");
    $saveString = "<h2>$newsTitle</h2>

    Read up a little on php strings and how you can use variables with them. Good luck!

    点赞 评论
  • douwu7168 2011-12-15 02:54
    $newsTitle = isset($_POST["title"]) ? "<h2>".$_POST["title"]."</h2>" : "Untitled";
    $submitDate = "<h3>".date("m/d/y g:iA")."</h3>";
    点赞 评论

相关推荐 更多相似问题