vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   search and trim ? (https://vborg.vbsupport.ru/showthread.php?t=48481)

fla5h 02-03-2003 04:38 PM

search and trim ?
 
I'm after a bit of help if someone can please lead me in the right direction.

I want a piece of PHP that will return me the host name of a url.

So

http://www.google.com/hello ..... = .... google.com
http://google.com/hello..... = .... google.com
www.google.com/hello..... = .... google.com

you get the picture ?

I have been trying to think of this logically ie

1. Search for 3rd '/' if it exists trim all to the right of it ( including '/' )
2. trim first 7 characters off the string.
3. Count the number of '.' in the string if more than one trim upto the first one.

So given

http://www.google.com/hello
step 1 = http://www.google.com
step 2 = www.google.com
step 3 = google.com

I cannot think of a better way ? Have I left a loop hole ?

If this follows through correctly, can someone let me know what I need to use in php to do this ?

Could do it in Javascript, but not php :(

Thanks for any guidance and help :)

fla5h 02-03-2003 06:30 PM

mmm, this seems a better way. :)

PHP Code:

<?php 
//Get the web site address
preg_match("/^(http:\/\/)?([^\/]+)/i""http://www.multi.part.domain.name.com/index.html"$matches);

$host $matches[2];

// get all but one segments of host name
preg_match_all("/\.([^\.\/]+)/",$host,$matches);

// first element does not want the period('.')
$matches[0][0] = $matches[1][0];
$domain implode('',$matches[0]);
echo( 
"Domain: " $domain);
?>



All times are GMT. The time now is 04:52 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01400 seconds
  • Memory Usage 1,712KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete