Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6353549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:25:56+00:00 2026-05-24T22:25:56+00:00

In the processPage function below, I’m grabbing the keywords from the keywords metatag of

  • 0

In the processPage function below, I’m grabbing the keywords from the keywords metatag of each URL processed. I need to alter the preg_split so that it only pulls the first three words of any keyword cluster.

For example, given this keywords meta tag:

<meta name="keywords" content="this is too long, this is not, keyword three" />

I only want the “this is too” part of the first keyword cluster.

Also, if the total list of keyword phrases is longer than 10, I only want to pull the first 10 keyword phrases from the list.

ie, (keyword phrase 1, kw 2, kw 3, kw4, etc…, keyword phrase 10)

Any help much appreciated.

<?php

class ResultPage
{
    function __construct($siteurl){$this->url = $siteurl;$this->processPage();}

    public $url;
    public $title;
    public $html;
    public $plainText;
    public $wordList;
    public $keywords = array();

    function processPage(){
        $this->html = rseo_keywordSearch_scrapePage($this->url);
        $dom = str_get_html($this->html);
        $metakws = $dom->find('meta[name=keywords]');
        if(count($metakws)){
            $metakw = $metakws[0];
            if($metakw->content){
                $this->keywords = preg_split("/[\s]*[,][\s]*/",$metakw->content); //EDIT HERE
                }
            }
        }

    public function GetResults(){
        return rseo_keyword_getCountArray($this->wordList);
    }
}


/*
 * 
 * Calls remote web page using cUrl, 
 * and returns the raw html
 * 
 */
function rseo_keywordSearch_scrapePage($url, $headonly = TRUE ){

    $agents = 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_USERAGENT, $agents);
    //curl_setopt($ch, CURLOPT_NOBODY, $headonly);
    curl_setopt($ch, CURLOPT_URL, $url);

    $curlResp = curl_exec($ch);
    curl_close($ch);
    $resp = str_replace("class=l","class='l'",$curlResp);

    return $resp;
}

function rseo_keyword_getCountArray($arr){
    $retarr = array_count_values($arr);
    arsort($retarr);
    return $retarr;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:25:56+00:00Added an answer on May 24, 2026 at 10:25 pm

    This is a bit easier matching rather than splitting, e.g.:

    preg_match_all('/(?<=^|,)\s*((?:[^\s,]+\s*){1,3})/', $metakw->content, $m);
    $this->keywords = array_slice($m[1], 0, 10);
    
    print_r($this->keywords);
    
    /*
    Array
        (
            [0] => this is too 
            [1] => this is not
            [2] => keyword three
        )
    */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using a drop-down list that's populated from database fields, i need to select an
I need to extract a value from a process array to myArray: File: MyClass.vb
Here's my issue: I need to close a process, already running, from a C#
In the script below, I'm getting an error when the URL is not found
I need to create content that only outputs what I entered, no layout, no
I have two classes, Base and Derived . I provide a function that applies
I created a C++ DLL function that uses several arrays to process what is
I would like to know why we need hierachical page tables in OS that
I have a list of strings that I need to pass to a process
I want to retrieve all the nodes present in particular DIV element.see the below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.