增量 BR 标签计数器不工作,缺少某些内容



我有以下代码,以便在每个BR标记旁边添加一个增量计数器,作为抒情歌曲的每行计数器,但它不起作用。需要帮助!

<?php $lyrics = "<p>Every time when I look in the mirror <br />All these lines on my face getting clearer <br /> The past is gone <br /> And it went by, like dusk to dawn <br /> Isn't that the way? <br /> Everybody's got their dues in life to pay <br /> Yeah, I know nobody knows <br /> Where it comes and where it goes <br /> I know it's everybody's sin <br /> You got to lose to know how to win <br /></p>";
$arr=explode(PHP_EOL, $lyrics);
foreach($arr as $index=>$ele)
{
echo $ele . $index+1 . "<br />";
} ?>

您正试图在PHP_EOL常量上拆分字符串$lyrics(这是一个依赖于平台的常量,指的是操作系统使用的行结束(。相反,您应该尝试按<br />拆分字符串。

这样尝试:使用"CCD_ 2";分离并使每个回波单一:

$lyrics = "<p>Every time when I look in the mirror <br />All these lines on my face getting clearer <br /> The past is gone <br /> And it went by, like dusk to dawn <br /> Isn't that the way? <br /> Everybody's got their dues in life to pay <br /> Yeah, I know nobody knows <br /> Where it comes and where it goes <br /> I know it's everybody's sin <br /> You got to lose to know how to win <br /></p>";
$arr=explode("<br />", $lyrics);
foreach($arr as $index=>$ele)
{
echo $ele;
echo $index+1;
echo "<br />";
}

最新更新