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

Retrieve Tag Elements

SpaceshipSpaceship
SpaceshipSpaceship
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
•••
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

New in Parking: updated way to act on many domains or inquiries at once
Your domain list and inquiry list now have a bar above and below the list. Check the items you want, then choose an action in the bar...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back