/    Sign up×
Community /Pin to ProfileBookmark

why preg_match is not work i want to pick title and 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 ?

__(Image removed: please create sample code for an example here that does not contain offensive content/language ~ Mod.)__

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 19.2019 — I'd strongly recommend using the PHP DOM functions to do this: it's much more robust and won't break as soon as there's the slightest change in the HTML you're scraping.
Copy linkTweet thisAlerts:
@VITSUSAJun 20.2019 — You can use PHP DOM functions to resolve this problem.
Copy linkTweet thisAlerts:
@adityaJun 20.2019 — how people will resolve my problem Our image removed by Mod.

i am strongly use preg_match php i will be not using HTML DOM.HTML is old language .I don't like
Copy linkTweet thisAlerts:
@adityaJun 20.2019 — @VITSUSA#1605132 i am strongly use preg_match php i will be not using HTML DOM
Copy linkTweet thisAlerts:
@NogDogJun 20.2019 — <i>
</i>if(preg_match('/previewTitle'&gt;(.*?)&lt;/', $match, $matches_title)) {

Will (.*?) contain other HTML tags? If so, the match will terminate at the opening "<" of the first such tag. (This is just one reason that using the DOM class is generally better for scraping HTML.)
×

Success!

Help @confectiepak spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...