Results 1 to 3 of 3

How do i do this?

This is a discussion on How do i do this? within the General Discussion forums, part of the vBSEO SEO Plugin category; Hello, I have this:- PHP Code: $var  =  "Community for India" ;  I want it to be like this:- PHP Code: $var2 ...

  1. #1
    Senior Member webwizzy's Avatar
    Real Name
    Vinayak
    Join Date
    Aug 2008
    Location
    India
    Posts
    257
    Liked
    0 times

    How do i do this?

    Hello,

    I have this:-

    PHP Code:
    $var "Community for India"
    I want it to be like this:-

    PHP Code:
    $var2"community, india"
    So, all I want is to strip the keywords out of the phrase and have them separated with a comma. How do I do this? And can it be done without vbseo.

    Thank you

  2. #2
    Senior Member Shadab's Avatar
    Real Name
    Shadab
    Join Date
    Oct 2007
    Location
    Bhopal
    Posts
    821
    Liked
    0 times
    Blog Entries
    12
    I don't know how to deal with Regular Expressions, so can't use the preg_replace() function.
    Going the long way... (though not foolproof)

    PHP Code:
    <?php

    $string 
    "A Community in Orkut for India";
    $stopwords = array('a','an','the','for','is','am','in');
    $count 0;

    $word_array explode(" "$string);
    $word_array array_map("strtolower"$word_array);

    // echo "<pre>" . $string . "\n\n";
    // print_r($word_array);

    foreach($word_array as $word)
    {
        foreach(
    $stopwords as $stop)
        {
            if(
    $word == $stop)
            {
                unset(
    $word_array[$count]);
            }
        }
        
    $count++;
    }

    $keywords implode(", "$word_array);

    // print_r($word_array);
    // echo "\n" . $keywords . "</pre>";

    ?>
    $string has A Community in Orkut for India
    $keywords has community, orkut, india

  3. #3
    Senior Member webwizzy's Avatar
    Real Name
    Vinayak
    Join Date
    Aug 2008
    Location
    India
    Posts
    257
    Liked
    0 times
    Thanks.. it works great.

    But I would still like a shorter version of the code using regexp.

    thanks

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •