Home > other >  Incremental BR tag counter isn´t working, something is missing
Incremental BR tag counter isn´t working, something is missing

Time:02-08

I have the following code, in order to add an incremental counter next to each BR tag, as a per line counter for a lyric song, but it isn´t working. Help is apreciated!

<?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 />";
} ?>

CodePudding user response:

You are trying to split the string $lyrics on the PHP_EOL constant (This is a platform dependent constant which refers to the line ending your operating system uses). Instead you should try to split the string by <br />.

CodePudding user response:

Try it this way: use "<br />" to separate and make each echo single:

$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 />";
}
  •  Tags:  
  • Related