Jump to content

Recommended Posts

Hello All,

 

I have a list of URLs submitted by users. I want to make sure: list has no White-spacing, and it contains only host values

i.e site.com,subdomain.site.com,site2.com,site3.net

 

I have the following code at the moment

 

var list = document.getElementById( "list" ).value ;

 

Taking out the white spaces in list

$vars = array_map('trim', explode(',', $list));  

is $list ok here? I am a newb and not sure the diff b/w $ and var

 

making sure list only contains host values of the intended URLs (from php manual)

 

function getHost($list) { 
   $parseUrl = parse_url(trim($list)); 
   return trim($parseUrl[host] ? $parseUrl[host] : array_shift(explode('/', $parseUrl[path], 2))); 
} 

This would only work for one address at a time, can some one help me to make it work for the whole list? Need to iterate this method through the comma separated list

 

Appreciate all your help. :)

 

Hi,

 

Thanks for the reply and help.

It was pointed out to me that

var list = document.getElementById( "list" ).value ;

is Javascript when I try the php code it just won't even submit the form.

 

This is what i have so far.

 

function startProcess() 
{
	var channelname = document.getElementById( "channelname" ).value ;		
	var sitename = document.getElementById( "sitename" ).value ;
	//sending private url example.com or null
	var privateurl = document.getElementById( "privateurl" ).value ;
	//?sending privateURL check 1 or 0?
	var privateurlcheck = document.getElementById( "privateurlcheck" ) ;
	//no value with nothing , checked always 0, with value it is 0
	//sending new values		

	if (privateurlcheck.checked == true) {
	var privateurlcheck = 1;
	// do something
	} else {
	var privateurlcheck = 0;}

	$vars = array_map('getHost', explode(',', $privateurl));

	http.open('get', "ajax/createchannel.php?channel=" + channelname + "&sitename=" + sitename + "&privateurl=" + privateurl + "&privateurlcheck=" + privateurlcheck);
	http.onreadystatechange = handleProcessResponse;
	http.send(null);
}

function getHost($url) 
{ 
	$parseUrl = parse_url(trim($url)); 
	return trim($parseUrl[host] ? $parseUrl[host] : array_shift(explode('/', $parseUrl[path], 2)));
}

Thanks for pointing that out. I realised this and now focusing on doing this on JavaScript

 

var list = document.getElementById( "list" ).value ;
var host = getHostname(str);

function getHostname(str) {
var re = new RegExp('^(?:f|ht)tp(?:s)?\://([^/]+)', 'im');
        return str.match(re)[1].toString();
}

 

I think above will just get rid of  ftp://, http://, and https:// prefixe but nothing more. Any ideas?

Hello Again to all the JavaScript pros. I've been moved here from php!

 

I have the following code and I want to make sure the [var privateurl] only contains comma separated host list

Originally when clients submit privateurl it would be a list with full urls and white space

 

i.e http://www.phpfreaks.com, domain.com/index.php, sub3.domain2.com,    site3.com

I want the list to be phpfreaks.com,domain.com,sub3.domain2.com,site3.com so that no white spaces and only host values of urls are sent to database.

 

 

var channelname = document.getElementById( "channelname" ).value ;		
	var sitename = document.getElementById( "sitename" ).value ;
	//sending private url example.com or null
	var privateurl = document.getElementById( "privateurl" ).value ;
	//?sending privateURL check 1 or 0?
	var privateurlcheck = document.getElementById( "privateurlcheck" ) ;
	//no value with nothing , checked always 0, with value it is 0
	//sending new values		

	if (privateurlcheck.checked == true) {
	var privateurlcheck = 1;
	// do something
	} else {
	var privateurlcheck = 0;}

	$vars = array_map('getHost', explode(',', $privateurl));

	http.open('get', "ajax/createchannel.php?channel=" + channelname + "&sitename=" + sitename + "&privateurl=" + privateurl + "&privateurlcheck=" + privateurlcheck);
	http.onreadystatechange = handleProcessResponse;
	http.send(null);
}

 

I have found teh following code

 

function getHostname(str) {
var re = new RegExp('^(?:f|ht)tp(?:s)?\://([^/]+)', 'im');
return str.match(re)[1].toString();
}

 

but was told it will only get ride of http, https, ftp

Can some one please help me with this?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.