SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Strip http:// from search

    I have a search function on my site that allows people to search keywords or urls.

    I want to remove the "http://" when people do a search for a url leaving it www.something.com

    I have figured out it will be something like:

    PHP Code:
    return ereg_replace("(https?)://"""$url); 
    But i am not 100% sure and no matter where I put it in my code, it doesn't work.

    Can anyone shed some light on how to do this?

    I have attached the php file that controls the search functions for my site in case you would like to see it.

    Thanks,

    Geoserv.
    Attached Files Attached Files

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Code:
    $url = 'http://website.com' ;
    
    $subject=  ereg_replace("(https?)://", "", $url);
    
    echo $subject ;
    Just assign it to another variable

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @Cups, thanks for taking the time to look and reply.

    I am having difficulty with where to apply the function, like I said, no matter where I place it, it doesn't seem to do anything.


    Geoserv.

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I spent a few mins looking at it, and the closest place I can see where it would be used is in this function:

    PHP Code:
        function explode_search($search_field$words){
            
    $sq '';

            foreach(
    explode(' ',$words) as $v){

    // $v should be a word, so strip off the http:// part

                
    $sq .= $search_field " LIKE '%".trim($v)."%' OR ";

            }

            return 
    substr $sq0, -);
        } 
    Why not just filter it out before evoking this class? You know where the user is filling in the form, and you know where you are evoking the class ...

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have tried assigning something to $v, but probably not soing it right.

    PHP Code:
        function explode_search($search_field$words){
            
    $sq '';
            
    $v ereg_replace("(https?)://"""$url);
            echo 
    $v ;
            foreach(
    explode(' ',$words) as $v){
                
    $sq .= $search_field " LIKE '%".trim($v)."%' OR ";
            }
            return 
    substr $sq0, -);
        } 
    But that doesn't effect the search result in the way I am looking for.

    Looks like this is above my head.


    Geoserv.

  6. #6
    Floridiot joebert's Avatar
    Join Date
    Mar 2004
    Location
    Kenneth City, FL
    Posts
    823
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function explode_search($search_field$words){
            
    $sq '';

            foreach(
    explode(' 'preg_replace('#https?://#i'''$words)) as $v){ 


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
  •