SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Zealot thetzfreak's Avatar
    Join Date
    Aug 2004
    Location
    United States
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How To Grab The URL From a Search

    Hi,

    I'm trying to grab a URL from a normal Google search, but I just can't think of how and what functions to use. Let's say I just want to search google for: "classical music" Bach. The search could be anything. How would I go about getting this google URL with this search? Perhaps there's a way to make this search behind the scenes where the search doesn't come up?

    My main goal is to then get the URL, and open the file using the file() function.

    Thanks for the help!

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    http://www.google.com/search?q=search+replace+spaces+with+a+plus+sign
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Zealot thetzfreak's Avatar
    Join Date
    Aug 2004
    Location
    United States
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    http://www.google.com/search?q=search+replace+spaces+with+a+plus+sign
    Well, I thought about this, but this is not a smart way to go because people often put special characters into their search, such as & signs, people use google-specific codes such as "define:" and quotes, and other such things. These things can only create problems. Perhaps someone can help me with a code that can fetch the url of a search? For example, if on page A I just make a form with a text input and type something there, it'll tell me on page B the url to Google of the search terms I put on page A.

    Thanks for the suggestion though!

  4. #4
    SitePoint Enthusiast Chousho's Avatar
    Join Date
    Jun 2006
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Couldn't you do an htmlspecialchars for the special characters, then a ereg_replace for the space to + ?

  5. #5
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    ummm urlencode ring a bell?

    http://php.net/urlencode

    will turn spaces and not web safe charas into something safe.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

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