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

  • Home
  • SEARCH
  • 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 4620174
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:31:29+00:00 2026-05-22T02:31:29+00:00

I need help understanding how to implement this part of PHP code in Ruby.

  • 0

I need help understanding how to implement this part of PHP code in Ruby.
Before thinking, “OMG! THIS IS A LOT OF CODE,” I just want to let you know the tiny section below is the relevant code to the question, but I included more below as I have the tendency to not include important facts in my questions (I’m a noob.) This script is for a SERP checker with the aim to teach me to program :

        ob_start();
        include_once($fetch_url);
        $page = ob_get_contents();
        ob_end_clean();  

        $page = str_replace('<b>','',$page);
        $page = str_replace('</b>','',$page);
        //preg_match('/008000\">(.+)<\/font><nobr>/i', $page, $match);
        preg_match_all('/<font color=#008000>(.*)<\/font>/', $page, $match);
        $r = 0;
        $position = '0';

My Ruby code is as follows:

def clean_up_keywords(str)
  str.gsub("\n", ",").delete("\r").split(',')
end

def clean_up_list(arr)
  arr.reject(&:empty?).each(&:lstrip!)
end

def make_strings_url_friendly(arr)
  arr.each do |e|
    e.gsub!(" ", "+")
  end
end

def make_urls(arr)
  arr.map {|e| "http://www.google.com/search?num=100&q=" + e}
end

post '/ranked' do
  dirty_list = clean_up_keywords(params[:keyword])
  clean_list = clean_up_list(dirty_list)
  url_ready_list = make_strings_url_friendly(clean_list)
  url_list = make_urls(url_ready_list)
end

The entire PHP script can be found here: http://pastie.org/1899806

The entire Ruby script can be found here: https://github.com/MelanieS/RankyPanky/blob/master/lib/rankypanky.rb

My deal is that I was told I don’t really have to implement the output buffer part because it’s Ruby, which is great for me because I can’t make heads or tails as to what it is even after several people explaining it to me. (Someday)

However, in the output buffer section, the $page variable is created. It is then used in the next section where it appears that it is removing bold. Does my Ruby script already take care of this?

Then, the SERP checker appears to be looking for results with that font color — and then what? putting them in an array called $match?

I was thinking, instead of having my code search for a font color, to have it search for the tag in the SERPs as it appears to be the only place where Google uses the cite thing… because the font tag type of search seems kind of deprecated to me.

I’m hoping that any one of you can tell me whether or not I am understanding this PHP code correctly and can give me a hint or two as to how to implement it in Ruby. My main issue is really knowing which elements of the PHP to NOT use since that whole output buffer thing has me baffled. Anything that points me in the right direction is much appreciated.

Also, in the original PHP code, it makes the Google urls like this (pseudocode):

"http://www.google.com/search?num=50&q=" +keyword+ "&btnG=Search"

But in my Ruby, I just made it like this:

"http://www.google.com/search?num=50&q=" +keyword

Does not adding the “&btnG=Search” to the end of the url make a difference? When I manually enter either url into my browser, it takes me to the same place, but I am unsure whether, programmatically, it makes a difference.

  • 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-22T02:31:30+00:00Added an answer on May 22, 2026 at 2:31 am

    It pulls the page into a variable, strips all the bold tags, then puts all the green text from the page (without the coloring) into the $matches array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need help with disk_total_space function.. i have this on my code <?php $sql=select
I need help on this following aspx code aspx Code: <asp:Label ID =lblName runat
I need help understanding some C++ operator overload statements. The class is declared like
I need help with this route map routes.MapRoute(Blog_Archive, Blog/Archive/{year}/{month}/{day}, new { controller = Blog,
I am newbie to db programming and need help with optimizing this query: Given
I need to implement a HtmlHelper extension in my MVC project simply just to
I'm writing a C++ program and I need some help understanding an error. By
I need help getting my head around the difference between my current OOP notion
I need help with the best practice to localize asp mvc apps, I saw
I need help to replace all \n (new line) caracters for in a String,

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.