【问题标题】:How to split text string in PHP (Song - Artist)如何在 PHP 中拆分文本字符串(歌曲 - 艺术家)
【发布时间】:2021-06-14 23:57:59
【问题描述】:

我有一点 PHP

 <?php
//get artist/title info
$artist = $_GET['artist'];
$title = $_GET['title'];

//create a temp file to store values for AJAX script
$r = fopen("temp_title.txt", "w");
fwrite($r, $artist." - ".$title);
fclose($r);

?>

我希望它在我的页面上显示为:

歌曲
艺术家

如何使歌曲以粗体显示,我将用什么代替“ - ”来换行?

【问题讨论】:

  • 您正在写入文本文件,没有bold 或任何其他样式格式,但换行符将是\n

标签: php html ajax


【解决方案1】:

假设你想生成一些可以被 AJAX 调用获取的 HTML,那么简单的方法就是做你想做的事

   fwrite($r, "<b>$artist</b><br>$title");

但是,这并不严格属于网络语义。您可能应该使用的是

   fwrite($r, "<h1>$artist</h1><br>$title");

(或 h1 到 h6 的一些变体)

要更好地控制实际外观,请使用类和一些 CSS

 fwrite($r, "<h1 class='artistName'>$artist</h1><br>$title");

您需要在页面中添加一些 CSS 以使艺术家姓名以粗体显示:

<style>
   h1.artistName {
        font-weight:bold;
        font-size:150%;
}
</style>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-13
    • 2017-02-22
    • 2014-07-13
    • 1970-01-01
    相关资源
    最近更新 更多