Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

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

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 />";
} ?>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report

0

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 />";
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!