Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 1, 2026.

Retrieve Tag Elements

Namecheap AuctionsNamecheap Auctions
NamecheapNamecheap
SpaceshipSpaceship
Watch

beaver6813

Established Member
Impact
16
Hey Guys,

Yet another question from me... sorry :santa:

Okay so say you had a meta tag for example:
Code:
<meta name="keywords" content="fun humor">
<meta name="description" content="this is a super site">
I have a snippet of code to retrieve an attribute from a specified tag:

Code:
function getAttribs($t, $a, $s)
	{
        preg_match_all("/(<".$t." .*?".$a.".*?=.*?\")(.*?)(\".*?>)/", $s, $m);
	return $m[2];
    	}

$t is the tag, $a is the attribute, $s is the content/code, $m is the new variable

But how would I find the content attribute for only the keywords tag? Since they both have the same tag name?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Something like that ?
PHP:
<?php
$content = '<meta name="keywords" content="fun humor">
<meta name="description" content="this is a super site">';
preg_match('/<meta +name=["\']?keywords["\']? content=["\'](.+)["\'] *>/i',$content,$matches);
echo $matches[1];
?>
=> fun humor
 
1
•••
1
•••
0
•••
0
•••
sdsinc said:
True but it's limited so I prefer to go with my regular expressions for parsing.
Infact, the get_meta_tags() function is far more efficient, and provides much more functionality.
 
0
•••
Olitt — high-converting AI websites, only from $1/moOlitt — high-converting AI websites, only from $1/mo

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back