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

94
March 20, 2022, at 03:20 AM

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

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 />.

Answer 2

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 />";
}
Rent Charter Buses Company
READ ALSO
How to add a button to remove user

How to add a button to remove user

I currently have this code that displays users on a team and when you click on the name of a user that is on the list it passes the name that you click to a function which removes them from the teamInstead I would like a button to be next to the name and when you click the button...

91
How to scroll the view to the location of a specific createjs element inside a canvas

How to scroll the view to the location of a specific createjs element inside a canvas

We are implementing documents electronic signature using createJS libraryWe collect the user signature and save it then we load the document in a canvas and mark the signature place in each page

116
How to make textfield mandatory based on value of pathfield in aem

How to make textfield mandatory based on value of pathfield in aem

My question is in aem dialog if we have two fields one is pathfield and another one is textfiled, Now I want to make textfield mandatory if some value is entered in pathfield and also if no value is entered in pathfield then I dont want to make textfield...

114
How can I use json response from php in jquery?

How can I use json response from php in jquery?

I'm trying to do a websiteI need to get all the reviews in the database

112