2

Im working on a website with videos, but I have a problem. When I try to make a list of videos using foreach every variable of it includes a space on end even after trying to use str_replace... nothing worked. Here is the code:

<?php
$serialy_ = explode("\n", $serialy);
foreach($serialy_ as $serial) {
?>
<div class="serial_card" style="background-image: url(<?php echo "titles/" . $serial . ".png"; ?>);">
    <h3><?php echo $serial; ?></h3>
</div>
<?php
}
?>
u1686_grawity
  • 452,512
Arty
  • 65
  • 3
    Your code as posted does not exhibit the symptom you describe. Please edit your post to include the initial value of $serialy. Just 4 or 5 lines should be sufficient. It seems likely that the extra spaces are in your data, and the problem is GIGO. – Jim L. Aug 12 '19 at 22:13

1 Answers1

3

I guess your line delimiter is \r\n and not\n then \r is shown as a space in a HTML page.

Change the $serialy_ = explode("\n", $serialy); into:

$serialy_ = explode("\r\n", $serialy);
Toto
  • 17,839