How to print only the value of group 2 in preg_match_all without the array and without loops
$url = 'https://hentaifox.com/gallery/58091/';
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
preg_match_all('!<a href="\/tag\/(.*?)\/"><span class="badge tag">(.*?)<\/span><\/a>!', $result, $tags);
I only want (.*?) result to use it any where
$group2=$tags[1];
print_r($group2);
but! Do not parse HTML with regex, use proper HTML parsing tools instead, in this case
$domd = @DOMDocument::loadHTML($result);
$xp = new DOMXPath($domd);
foreach ($xp->query("//a[contains(@href,'/tag/')]/span[1]") as $tag) {
$tags[] = trim($tag->textContent);
}
Isn't it possible to do something like that ?
$matches = preg_match_all('!<a href="\/tag\/(.*?)\/"><span class="badge tag">(.*?)<\/span><\/a>!', $result, $tags);
$group_2 = $matches[2][0][0];
(I'm no expert, so maybe you will have to change the numbers a little bit...)