0

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' ??

1
  • Are you trying to automatically format "description"? Commented Feb 27, 2015 at 20:25

5 Answers 5

1

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'
],
Sign up to request clarification or add additional context in comments.

1 Comment

If the transcription class is not preformatted text, you will want to use nl2br to convert the newlines to break tags.
1

In php you work with browsers, so you need to slip in "
" tag where you need a new line instead of "\n"

For example :

< ?php 
foreach ($myarray as $a){
    echo $a . "<br>";
}

1 Comment

PHP have nothing to do with browsers. HTML on the other hand does.
0

You just need to put

"\n"

In your string. Note that you must use double quotes.

So

"some text here\n will put in a line\nbreak";

1 Comment

I tried this, because in my mind thats what I was taught but it isn't working, nothing is being changed. i even put like \n\n\n\n\n and nothing happens.
0

You can just use \n which is converted to a line break when viewed. so:

description => "alot of text.... and some more/nThen on the next line",

Comments

0

Not sure do you want to have text in multiple line in web browser (HTML) or new lines in page source.

But anyway, you have to make up your mind - what text should represent new line (in your example code it's double space character, but not sure is it just example - can be something else) and search/replace it with "\n" if you want to have source well formatted or with <br/> tag if you want to have new line in the browser.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.