1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Can a PHP pro help me out really fast? Simple scrip

Discussion in 'Black Hat SEO' started by Ztak07, Mar 10, 2013.

  1. Ztak07

    Ztak07 Regular Member

    Joined:
    Jun 23, 2012
    Messages:
    389
    Likes Received:
    116
    I am terrible with coding and I dont understand PHP at all. I need a script when I give it a URL will strip the subdomain and give me a root domain. I have found this code

    PHP:
    $url 'http://google.com/dhasjkdas/sadsdds/sdda/sdads.html';
    $parse parse_url($url);
    print 
    $parse['host']; // prints 'google.com'
    Only problem is I need it to work with more than 1 at a time. Is there anyway to link this to a text field in HTML where I can mass 1 URL per line and it will return a root domain for each? I dont have much to offer for this but I have some high authority domain LISTS and I would be glad to give a high DA domain that is ready to register in exchange for help/
     
  2. the_demon

    the_demon Jr. Executive VIP

    Joined:
    Nov 23, 2008
    Messages:
    3,177
    Likes Received:
    1,563
    Occupation:
    Search Engine Marketing
    Location:
    The Internet
    Code:
    <?php
    # MASS URL STRIPPER - TO ROOT DOMAIN
    # BY, the_demon
    # of: www.blackhatworld.com
    $database_name = "myurls.txt"; // Be sure to put this file in same directory as your PHP script
    $urls_to_generate = file($database_name); //open up our database for processing
    ###BEGIN TO GENERATE THE LINKS###
    	foreach($urls_to_generate as $num=>$myurl) // FOR EACH LINE IN THE FILE PERFORM THE BELOW OPERATION(S)
    		{
    		$url_stripped_to_hostname = parse_url($myurl); //Grab the current url and
    		echo $url_stripped_to_hostname['host']; //strip the url to the base and echo it out to browser
    		echo'<br />'; //makes it one per line for nice and clean browser output
    		}
    ?>
    
    VERSION 2, THIS WILL REMOVE THE PREFIX: www.

    Code:
    <?php
    # MASS URL STRIPPER - TO ROOT DOMAIN
    # BY, the_demon
    # of: www.blackhatworld.com
    $database_name = "myurls.txt"; // Be sure to put this file in same directory as your PHP script
    $urls_to_generate = file($database_name); //open up our database for processing
    ###BEGIN TO GENERATE THE LINKS###
    	foreach($urls_to_generate as $num=>$myurl) // FOR EACH LINE IN THE FILE PERFORM THE BELOW OPERATION(S)
    		{
    			$url_stripped_to_hostname = parse_url($myurl); //Grab the current url and
    			
    			# REMOVE HASH SYMBOL ON NEXT LINE TO RE-ENABLE
    			# echo $url_stripped_to_hostname['host']; //strip the url to the base and echo it out to browser
    			
    			
    			#THIS SECTION WILL STRIP "www."
    			$my_url_2 = $url_stripped_to_hostname['host']; // GRAB THE HOST NAME
    			$string = $my_url_2; //This grabs it without the
    			$patterns = array();
    			$patterns[0] = '/www./'; // WWW. is what we'll be replacing
    			$replacements = array();
    			$replacements[0] = ''; //Replace it with nothing
    			echo preg_replace($patterns, $replacements, $string); // Spit out the end result		
    			
    			
    			echo'<br />'; //makes it one per line for nice and clean browser output
    		}
    ?>
    
    VERSION 3
    --> Strip all urls in list to host name
    -->THEN IT --> Removes www. prefix
    -->THEN IT --> Converts the url to all lower case

    This is useful if you download link lists from various places that had weird formatting or your excel file or GoDaddy export was in all caps

    Code:
    <?php
    # MASS URL STRIPPER - TO ROOT DOMAIN
    # BY, the_demon
    # of: www.blackhatworld.com
    $database_name = "myurls.txt"; // Be sure to put this file in same directory as your PHP script
    $urls_to_generate = file($database_name); //open up our database for processing
    ###BEGIN TO GENERATE THE LINKS###
    	foreach($urls_to_generate as $num=>$myurl) // FOR EACH LINE IN THE FILE PERFORM THE BELOW OPERATION(S)
    		{
    			$url_stripped_to_hostname = parse_url($myurl); //Grab the current url and
    			
    			# REMOVE HASH SYMBOL ON NEXT LINE TO RE-ENABLE
    			# echo $url_stripped_to_hostname['host']; //strip the url to the base and echo it out to browser
    			
    			
    			#THIS SECTION WILL STRIP "www."
    			$my_url_2 = $url_stripped_to_hostname['host']; // GRAB THE HOST NAME
    			$string = $my_url_2; //This grabs it without the
    			$patterns = array();
    			$patterns[0] = '/www./'; // WWW. is what we'll be replacing
    			$replacements = array();
    			$replacements[0] = ''; //Replace it with nothing
    			
    			# IN THE EVENT YOU ARE TRYING TO CLEAN UP A LINK LIST FROM WHERE EVER AND IT'S GOT CAPITAL LETTERS
    			# AND YOU WANT TO GET RID OF THAT, THIS VERSION WILL MAKE THE STRIPPED HOST NAME (ROOT DOMAIN NAME)
    			# ALL LOWER CASE.
    			
    			$str = preg_replace($patterns, $replacements, $string); //turn the url into a string for later processing
    			$str = strtolower($str); // conver the url to all lower case
    			echo $str; // Spit out the end result
    			
    			
    			echo'<br />'; //makes it one per line for nice and clean browser output
    		}
    ?>
    
     
    • Thanks Thanks x 1
    Last edited: Mar 10, 2013
  3. Ztak07

    Ztak07 Regular Member

    Joined:
    Jun 23, 2012
    Messages:
    389
    Likes Received:
    116
    Thanks but it says host wont work Undefined index: host in line 8
     
  4. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,287
    Likes Received:
    1,799
    Location:
    www.Indexification.com
    Home Page:
    try this one:

    <?php
    $urls=file('myurls.txt');

    foreach($urls as $url)
    {
    $url=trim($url);
    if(!empty($url) and preg_match('/^http/i',$url))
    {
    $tmp=parse_url($url);
    $domain=strtolower(preg_replace('/^(www\.)/i','',$tmp['host']));
    echo $domain.'<br />';
    }
    }
    ?>
     
  5. the_demon

    the_demon Jr. Executive VIP

    Joined:
    Nov 23, 2008
    Messages:
    3,177
    Likes Received:
    1,563
    Occupation:
    Search Engine Marketing
    Location:
    The Internet
    The script I coded works perfectly without error in all cases, I tested it on my server first. You may have copied my source code before I had saved the updated version of my post. Check to make sure you're using the most up to date code.

    See for yourself

    Source file: http://www.verdadmedia.com/tools/myurls.txt
    Example output: http://www.verdadmedia.com/tools/mass-url-stripper [VERSION #3]


    Are you trying to fetch a url on a remote website?
    Cause then the code will need to be different.


    Based on the error you're reporting it sounds like you didn't upload the text file to your server with your urls AND OR you didn't properly name the file to match the code.
     
    Last edited: Mar 10, 2013
  6. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,287
    Likes Received:
    1,799
    Location:
    www.Indexification.com
    Home Page:
    it will return him the error he pasted if there are empty lines or malformed urls.. but those are just warnings and nothing more..
     
  7. Ztak07

    Ztak07 Regular Member

    Joined:
    Jun 23, 2012
    Messages:
    389
    Likes Received:
    116

    Error was my stupidity. It outputs stuff now, but the subdomains do not get removed. Also what if the website is like http://101.domain.com
     
  8. Ztak07

    Ztak07 Regular Member

    Joined:
    Jun 23, 2012
    Messages:
    389
    Likes Received:
    116
    He was right. www.subdomain.domain.com returns subdomain.domain.com instead of domain.com. Do either of you know how to fix this? Also there is a weird _ after each output. Looks like

    www.domain.com_domain.com_
     
  9. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,287
    Likes Received:
    1,799
    Location:
    www.Indexification.com
    Home Page:
    to get clean domain out of subdomain i regularly do this in a quick

    $host='subdomain.domain.com';
    $tmp=explode('.',$host);
    $domain=implode('.',array_slice($tmp,-2,2));

    but it works only for .com/.net.... doesn't work for .co.uk and etc... for those to work some additional checks should be added..
     
  10. Ztak07

    Ztak07 Regular Member

    Joined:
    Jun 23, 2012
    Messages:
    389
    Likes Received:
    116
    bump please help
     
  11. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,287
    Likes Received:
    1,799
    Location:
    www.Indexification.com
    Home Page:
    still didn't get it to work?

    put your urls in myurls.txt

    and use this code:

    <?php
    $urls=file('myurls.txt');

    foreach($urls as $url)
    {
    $url=trim($url);
    if(!empty($url) and preg_match('/^http/i',$url))
    {
    $tmp=parse_url($url);
    $domain=strtolower(preg_replace('/^(www\.)/i','',$tmp['host']));
    $tmp=explode('.',$domain);
    $domain=implode('.',array_slice($tmp,-2,2));
    echo $domain.'<br />';
    }
    }
    ?>