Unstoppable Domains โ€” Get your daily AI drops report

Retrieve Tag Elements

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
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
•••
CatchedCatched
Escrow.com
Spaceship
Domain Recover
CryptoExchange.com
Catchy
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back