Monday, 23 February 2015

PHP: Extract keywords from a webpage

The title said it all: A great code snippet to easily extract meta keywords from any webpage.
<?php
$meta = get_meta_tags('https://thiscode4u.blogspot.com/');
$keywords = $meta['keywords'];
// Split keywords
$keywords = explode(',', $keywords );
// Trim them
$keywords = array_map( 'trim', $keywords );
// Remove empty values
$keywords = array_filter( $keywords );

print_r( $keywords );
?>

0 comments:

Post a Comment