Search code examples
phparraysline-breaks

Putting line breaks in text within a PHP array


I have an array with a bunch of youtube video data that I call in a php file and populate a page. Basically in the array I have a lot of text ie a description of the video that I want to have line breaks.

Basically when I make this call, $description puts all the text on the same line, I want to make paragraphs or new lines on some of the text, but I'm not sure how to do that in the array.

<div class="transcription-container"><p class="transcription"><?php echo $**description** ?></p></div>

the array

    'youtube-video-key' => [
        'youtube-id' => 'aRtFSDvd5',
        '**description**' => LotsoftextLotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext  Lotsoftext     
        'title' => 'youtube-video-title',
        'url' => 'www.youtube.com/url',
        'time' => '1:59',
        'thumbnail' => '../../images/thumbnails/thumb2.jpg'
    ],

So in the array how would I go about putting new line breaks under 'description' ??


Solution

  • You can use \n as follows:

    'youtube-video-key' => [
        'youtube-id' => 'aRtFSDvd5',
        '**description**' => 'one line \n second line'     
        'title' => 'youtube-video-title',
        'url' => 'www.youtube.com/url',
        'time' => '1:59',
        'thumbnail' => '../../images/thumbnails/thumb2.jpg'
    ],