SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: Strip http:// from search
-
May 12, 2009, 07:39 #1
- 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);
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.
-
May 12, 2009, 07:59 #2
- 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 ;
-
May 12, 2009, 08:04 #3
- 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.
-
May 12, 2009, 08:43 #4
- 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 ( $sq, 0, -4 );
}
-
May 12, 2009, 09:03 #5
- 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 ( $sq, 0, -4 );
}
Looks like this is above my head.
Geoserv.
-
May 12, 2009, 09:12 #6
- 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