aditya56 Posted June 19, 2019 Share Posted June 19, 2019 I want to preg_match but now work need title and duration //Title if(preg_match('/previewTitle\'>(.*?)</', $match, $matches_title)) { $video['title'] = htmlspecialchars_decode(strip_tags(stripslashes($matches_title[1])), ENT_QUOTES); } else { $this->errors[] = 'Failed to get video title for '.$video['url'].'!'; if (!$this->debug) continue; else $debug_e[] = 'TITLE'; } //Duration if(preg_match('/label\'>(.*?)</', $match, $matches_duration)) { $video['duration'] = duration_to_seconds($matches_duration[1]); } else { $this->errors[] = 'Failed to get video duration for '.$video['url'].'!'; if (!$this->debug) continue; else $debug_e[] = 'DURATION'; } how to choose title ? how to choose duration ? I want to preg_match but now work need title and duration //Title if(preg_match('/previewTitle\'>(.*?)</', $match, $matches_title)) { $video['title'] = htmlspecialchars_decode(strip_tags(stripslashes($matches_title[1])), ENT_QUOTES); } else { $this->errors[] = 'Failed to get video title for '.$video['url'].'!'; if (!$this->debug) continue; else $debug_e[] = 'TITLE'; } //Duration if(preg_match('/label\'>(.*?)</', $match, $matches_duration)) { $video['duration'] = duration_to_seconds($matches_duration[1]); } else { $this->errors[] = 'Failed to get video duration for '.$video['url'].'!'; if (!$this->debug) continue; else $debug_e[] = 'DURATION'; } how to choose title ? how to choose duration ? Quote Link to comment https://forums.phpfreaks.com/topic/308866-preg_match-is-not-work-i-want-to-pick-title-and-duration/ Share on other sites More sharing options...
Psycho Posted June 30, 2019 Share Posted June 30, 2019 This is not a use case where you should be using RegEx. A better solution is to use a DOM parser such as Simple HTML Dom. You can easily find elements by searching by multiple parameters - such as tag and class. Using the above content you could get every DOM object for every Div with the class "previewSegment" - which would appear to hold all the contents for each title. Then use the DOM parser to get the text within the "previewTitle" div and the "previewLabel" (which is the runtime). That is how you should be doing this. But, it can be done via RegEx, I just wouldn't advise it. $regEx = "#<div class=\".*?previewLabel[^\"]*\">(.*?)</div>.*?<div class=\"previewTitle\">(.*?)</div>#is"; preg_match_all($regEx, $content, $matches, PREG_SET_ORDER); $titles = array(); foreach($matches as $match) { $titles[] = array( 'title' => $match[2], 'duration' => $match[1] ); } echo "<pre>".print_r($titles, 1)."</pre>"; Example output: Array ( [0] => Array ( [title] => Title of clip 1 [duration] => 6 min ) [1] => Array ( [title] => Title of clip 2 [duration] => 12 min ) ) Quote Link to comment https://forums.phpfreaks.com/topic/308866-preg_match-is-not-work-i-want-to-pick-title-and-duration/#findComment-1568043 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.