Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

Retrieve Tag Elements

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
NamecheapNamecheap
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
Close
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
Close
1
Close
0
Close
0
Close
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
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back