0

I'm trying to update a large number of videos on my youtube channel programmatically via the API as I also want to store the video information in my website DB.

Everything is working fine, except that I'm having real trouble rendering a new line in the description field.

I am writing the description in an html form, but there is a paragraph I want to be added to every video and so I've added this in the XML request data as follows:

'<media:description type="plain">'.$form->description." \n\n ".'This is the text I want automatically added to each video.
</media:description>'

New lines in my form data are fine, it is just the new lines before this last paragraph.

I've tried various combinations of \n and \r and this doesn't seem to be working.

DaveR
  • 2,355
  • 1
  • 19
  • 36
  • What does qualify a line-break in `$form->description`? Find that out and use it for the other line-breaks as well I'd say and you should be fine. – hakre May 18 '13 at 09:20
  • how can I read the raw content of that field including whatever characters create the new line? – DaveR May 18 '13 at 09:21
  • Please see: [How can I get a hex dump of a string in PHP?](http://stackoverflow.com/q/1057572/367456) for some PHP variants, if you're [using linux, there is a program called `hexdump` and friends](http://stackoverflow.com/q/2614764/367456). – hakre May 18 '13 at 09:24

3 Answers3

0

Check which character sets (code tables) you are using. Either by default or set by yourself. For example ASCII (when coding) or UTF-8 (when sending and receiving data transfers). Then use a PHP function to convert between them. For example iconv(). See also Convert utf8-characters to iso-88591 and back in PHP . If using ASCII then you can insert a 'newline' with the function chr(10). And a 'carriage return' with the function chr(13).

Community
  • 1
  • 1
Als
  • 1,387
  • 1
  • 10
  • 5
0

I found a way: just use PHP_EOL to encode a linebreak ;-)

linus
  • 1
  • 2
    You could post a link to references and an example to enhance your answer ;) – mathielo Oct 01 '13 at 21:17
  • My PHP core library says `define('PHP_EOL', "\n");` and that's what Dave is already using. I don't think that this will help. – flu Oct 01 '13 at 21:19
0

Have you tried putting it inside a CDATA element?

'<media:description type="plain"><![CDATA[' . $form->description . "\n\n" .
'This is the text I want automatically added to each video.]]></media:description>'

Maybe it's simply parsed away by the YouTube API as long as it isn't marked as being raw.

You could also try:

'<media:description type="plain"><![CDATA[' . $form->description . '<br/><br/>' .
'This is the text I want automatically added to each video.]]></media:description>'

...if the API supports HTML formatting. By putting it inside the CDATA element you don't need to escape it.

flu
  • 14,307
  • 8
  • 74
  • 71