/    Sign up×
Community /Pin to ProfileBookmark

why preg_match is not work include two title same page

Title tag use in same page one is button tag other is p tag button tag is first title=”watch later” other on a href tag title we want to import second a href tag title
source code
image
https://i.imgur.com/AUrk0j7.png
https://i.imgur.com/ieuZsHk.png
https://i.imgur.com/ufRsX6d.png
i have tried many things to change /title but it import title is “watch later” i want second title import
//Title
if(preg_match(‘/title=”(.*?)”/’, $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’;
}

how to choose second title under a tag ?
i want to remove watch later title .

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 14.2019 — $matches_title will be a 2-dimension array, so you'll probably want $matches_title[1][1].
<i>
</i>$ php -a
Interactive shell

php &gt; $text = 'This is="a test". It is="only a test"';
php &gt; preg_match_all('/is="(.*?)"/', $text, $matches);
php &gt; print_r($matches);
Array
(
[0] =&gt; Array
(
[0] =&gt; is="a test"
[1] =&gt; is="only a test"
)

<i> </i>[1] =&gt; Array
<i> </i> (
<i> </i> [0] =&gt; a test
<i> </i> [1] =&gt; only a test
<i> </i> )

)
php &gt;
Copy linkTweet thisAlerts:
@NogDogJun 14.2019 — PS: Using the [DOM Object Model](https://php.net/dom) would probably be a more robust method.
Copy linkTweet thisAlerts:
@adityaauthorJun 15.2019 — @NogDog#1604740

@NogDog#1604739

yes it is working fine.
Copy linkTweet thisAlerts:
@adityaauthorJun 15.2019 — hello webdeveloper team please remove this page https://www.webdeveloper.com/d/384904-why-preg-match-is-not-work-include-two-title-same-page
×

Success!

Help @aditya 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.19,
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,
)...