Matt1972
-
Posts
3 -
Joined
-
Last visited
Posts posted by Matt1972
-
-
4 minutes ago, Barand said:
Perhaps you could explain the rationale behind this method for getting the title...
$num = rand (0, intval (count ($titles) / 3)) * 3
@Barand To be honest I had found that code online that I used with a Youtube script. I'm not even sure if that is the correct way to do it. I'm learning php so really kinda just fumbling through this.
-
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'm not an advance programmer so not sure if I am even approaching this correct way. Here is the code I have that is responsible for putting the title in. I appreciate your help.
$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’; }
(HELP) PHP to get random line from text file for video embed
in PHP Coding Help
Posted
@Barand So are you saying replace this line:
With this line:
So I would end up with this:
I tried to run my script with that but it still does not work. Below is the entire php file for this script.