This is a section of my code that goes and gets videos from any video site. What I’m having issues with is having it post a random title, that are all in a text file called titles.txt. What I’m wanting to accomplish is have my script go pull the video embed code, the duration, the tags, etc. Which all works fine until I get to the title part where it pulls locally from the server from the text file. I get a 500 error in the browser when I try to run the script. Here is the code I have that is responsible for putting the title in.
$video = array(
'user_id' => $this->user_id,
'status' => $this->status,
'site' => 'my site',
'id' => '',
'embeddable' => true,
'url' => '',
'titles' => '',
'title' => '',
'description' => '',
'tags' => '',
'category' => '',
'thumbs' => array(),
'duration' => 0,
'embed' => ''
);
function random_title ()
{
$titles = file ("titles.txt", FILE_IGNORE_NEW_LINES);
$num = rand (0, intval (count ($titles) / 3)) * 3;
return ucwords($titles[$num]);
}
//Title
if(preg_match('/title="(.*?)"/', $match, $matches_title)) {
$video['title'] = random_title(). ' - My site name';
} else {
$this->errors[] = 'Failed to get video title for '.$video['url'].'!';
if (!$this->debug) continue;
else $debug_e[] = 'TITLE';
}