mssakib Posted May 9, 2013 Share Posted May 9, 2013 HIThis function is to check a site/ip's ping time in ms But it wont work if i add http:// . It works for google.com but if i add http://google.com it wont work. Here is the function function ping($host, $port, $timeout) { $tB = microtime(true); $fP = fSockOpen($host, $port, $errno, $errstr, $timeout); $errMsg = 'The Site is Down</p>'; if (!$fP) { return $errMsg; } $tA = microtime(true); $reSult= round((($tA - $tB) * 1000), 0); return $result; } Need help guys Quote Link to comment https://forums.phpfreaks.com/topic/277844-function-problem/ Share on other sites More sharing options...
ignace Posted May 9, 2013 Share Posted May 9, 2013 So what is the problem? Simply leave out http://. fsockopen only takes a server address. Quote Link to comment https://forums.phpfreaks.com/topic/277844-function-problem/#findComment-1429329 Share on other sites More sharing options...
mssakib Posted May 9, 2013 Author Share Posted May 9, 2013 But i want to use http:// any way to do so ? Quote Link to comment https://forums.phpfreaks.com/topic/277844-function-problem/#findComment-1429366 Share on other sites More sharing options...
requinix Posted May 9, 2013 Share Posted May 9, 2013 You can't have it in there. Period. Why do you think you want it? Quote Link to comment https://forums.phpfreaks.com/topic/277844-function-problem/#findComment-1429367 Share on other sites More sharing options...
mssakib Posted May 10, 2013 Author Share Posted May 10, 2013 I added that fuction to a website. But Some users are adding site using http:// Quote Link to comment https://forums.phpfreaks.com/topic/277844-function-problem/#findComment-1429418 Share on other sites More sharing options...
Jessica Posted May 10, 2013 Share Posted May 10, 2013 So there's a fairly obvious step to take.... Quote Link to comment https://forums.phpfreaks.com/topic/277844-function-problem/#findComment-1429421 Share on other sites More sharing options...
buzzycoder Posted May 10, 2013 Share Posted May 10, 2013 You can use str_replace.For e.g <?php echo str_replace("Coder","Developer","Buzzy Coder"); ?> On above code,I had replaced string from "Buzzy Coder" to "Buzzy Developer".I had just changed a word "Coder" to "Developer".You can use below code as an example for your issue. <?php echo str_replace("http://","","http://www.google.com"); ?> Add above code to your POST or GET method variable,from which you're getting the user input. Hope it helps you! Quote Link to comment https://forums.phpfreaks.com/topic/277844-function-problem/#findComment-1429429 Share on other sites More sharing options...
AbraCadaver Posted May 13, 2013 Share Posted May 13, 2013 if( $host = parse_url($host, PHP_URL_HOST) ) { //host is good } else { //host is bad } Quote Link to comment https://forums.phpfreaks.com/topic/277844-function-problem/#findComment-1429912 Share on other sites More sharing options...
mssakib Posted May 13, 2013 Author Share Posted May 13, 2013 thx guys will try these Quote Link to comment https://forums.phpfreaks.com/topic/277844-function-problem/#findComment-1429915 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.