Click here to Skip to main content
15,868,016 members
Articles / Web Development / HTML

Generating URL Names With Prefix/Suffix

Rate me:
Please Sign up or sign in to vote.
2.15/5 (6 votes)
2 May 2012CPOL5 min read 29K   4   7
Generating URL Names With Prefix/Suffix

Updated

This article has been updated. It was suggested that the domain name be checked for availability. This capability is now included. My original intent was for this program to serve as a memory aid or marketing tool.

I did not intend on the program's suggestions to be final; rather I intended the words to be suggestions to provoke creative thought. But, it seems readers are more inclined to want to go entirely with the suggested word list. Thus, I have responded to that need. 

Introduction

Computers are well designed for mundane repetitive tasks. Providing a suggested list of URL names is a good example.

Image 1

Background

A web designer generally knows the basic URL name they would like to have, however the most common names are likely already taken. The easiest way around this is to provide a snappy prefix or suffix word that will serve to brand the product. This program takes a list stored in the program by the user and prints out all combinations.

Suppose we have a customer that makes wedding cakes. If we provide "Cake", our list of suggestions might include "LaserCake", "MaxiCake", "QuickCake", "SuperCake", "CakeMan", "CakeHut", etc. The beauty of this program is that we can quickly try several base names and see a list of hundreds if not thousands of combinations.

For example we might want to try "Cake", "Frosted", "Food", "Party", "Desert", and see what interesting combinations may result.

Image 2

Most commercial domain name providers do provide some form of domain name suggestion. But they have several important limitations. Suggestions may include the purchasers name. This is inappropriate for someone seeking a name for a client. Also, the suggestions lack intelligence toward preferences that we may have. This program allows us to adjust for this.

The second issue is that domain names are significantly effected by the industry they represent.  If the client is associated with boating or water sports, the domain provider will probably not include suggestions that have "wet", "ski", "water", "hydro", or "wave". 

I make copies of this program for each major industry. For example I have a program for "Landscape or Realty" words, another has "Engineering and Tech" style words, and so forth. I find that about 50 prefixes and 100 suffixes tailored to a specific industry will pump out enough suggestion that one of them will give me a really good idea for a Url name :)

Step 1: Simple URL name form

For this application we will use PHP. The application can be placed on a web site or used from our "local" web development envirionment such as WAMP, MAMP or XAMP.

C++
<?php

/* 
 +--------------------------------------------------------------------+
 |  file:       url_names.php                  version:  2012-05-01   |
 |  by:         Jan Zumwalt - NeatInfo.com                            |
 |  copyright:  GNU GENERAL PUBLIC LICENSE                            |
 |              <a href="http://www.gnu.org/copyleft/gpl.">www.gnu.org/copyleft/gpl.</a>                             |
 |  purpose:    User supplies web name, program adds prefix and       |
 |              suffix words from array list.                         |
 +--------------------------------------------------------------------+  */
       
  // make things pretty using dark theme     
  echo"
  <head>
    <style>
      body {
       font-size        : 12 pt;
       font-family      : arial;
       color            : #ffb;   /* yellow font color */
       background-color : #123;   /* dark navy bk ground */     
       line-height      : 12pt;
       margin           : 75px;  
      }
    </style>
  </head>
  <body>
  ";


<!-- code to be added -->


// +--------------------   show input form   ---------------------+
  echo "
  <form name='inputform' action=' " . $_SERVER['PHP_SELF'] . " ' method=\"get\">
    URL Name: <input type='text' width='100' maxlength='100' name='name' />
    <input type='submit' value='Submit' />
    <INPUT type='reset' />
    <br><br><b><span style='color:#e33;'>Be patient, this may take several minutes!</span></b>
  </form> 
  ";

?> 

We start with a simple CSS attractive theme and basic HTML FORM that allows the user to enter a proposed URL name. In this example lets assume that we are going to set up a site for someone in the cooking, restaurant, or baking industry.

You notice that the form uses the php $_SERVER['PHP_SELF'] to call itself when the submit button is pressed. The word that the user entered is passed as a variable in $_GET['name'].

We can run the program at this point but it won't do anything because the variable being passed is not processed.

Step 2: Store prefix and suffix words in array

Next we store the list of prefix and suffix words that will be added to the URL name.

Now I must confess that the word list that I have provided is VERY generic. I consider my personal word list to be sort of a trade secret. But, careful thought will allow you to really expand on this list. For example I consider words like "Web", "Fire", and "Hot" to be great prefixes. Good suffixes include "Wiz", "Man", and "Mart".

PHP
      // words to be added at the beginning      
      $prefix  = array(
        "Cool",
        "Fast",
        "Fire",
        "Fry",
        "Hot",
        "Maxi",
        "Quick",
        "Sugar",
        "Super",
        "Sweet",
        "Web",
        "X",
        "Xtra"
      );

 

PHP
      // words to be added at the end
      $suffix = array(        
        "Dog",
        "Hut",
        "Kid",
        "Kit",
        "Man",
        "Power",
        "Pro",
        "Shop",
        "Shot",
        "Store",
        "Wiz",
        "World"
      );

Each word in the array will be echoed to the browser and displayed.

Now we need to add code to process the users input (if it exists). We check to see if the user has submitted a URL name. It will be passed in the $_GET['name'] variable and should not be empty.

Step 3: Process user input and add prefix/suffix

Next we process a list of prefix or suffix words provided in the arrays and print them out. We use a loop to process each word in the array - one at a time. We also use the PHP checkdnsrr($name, $type) function to test and see if the domain name has been registered. If the domain name is unregistered, the .com extension is show in green letters. To keep things tidy, we use a html table to format the output.

PHP
    /* +----------------------------------+
       |          process PREFIX          |
       +----------------------------------+  */
    echo "<br><span style='color:#e33;'><h1>Prefix</h1></span>"; // word list title
    echo "<table>";   
    
    foreach($prefix as $item) {  // add each prefix and show
      echo "<tr><td>"$item . $urlname . "</td>";

      // check if .COM domain name exists
      $name = $item . $urlname . ".com";  
      $type = "ANY";   // domain type may be any of: A, MX, NS, SOA, PTR, CNAME, AAAA, A6, SRV, NAPTR, TXT or ANY.  
      
      if (checkdnsrr($name, $type)) {   
        echo "<td><span style='color:#e33;'>[.com]</span></td>"; // this is a registered domain
      } else {
        echo "<td><span style='color:#6fa;'>[.com]</span></td>"; // this domain doesn't exist!
      } // end of domain check    
      
      echo "</tr>";
      
    }   // end of each prefix
    echo "</table>";

The above example shows how prefixes are processed. Suffixes are processed in the same manner.

Step 4: Put it all together

Lets put all the code together with prefix and suffix sections.

PHP
<?php

/* 
 +--------------------------------------------------------------------+
 |  file:       url_names.php                  version:  2012-05-01   |
 |  by:         Jan Zumwalt - NeatInfo.com                            |
 |  copyright:  GNU GENERAL PUBLIC LICENSE                            |
 |              <a href="http://www.gnu.org/copyleft/gpl.html">http://www.gnu.org/copyleft/gpl.html</a>                  |
 |                                                                    |
 |  purpose:    User supplies web name, program adds prefix and       |
 |              suffix words from array list.                         |
 +--------------------------------------------------------------------+  */
       
  // make things pretty using dark theme     
  echo"
  <head>
    <style>
      body {
        font-size        : 12 pt;
        font-family      : arial;
        color            : #ffb;   /* yellow font color */
        background-color : #123;   /* dark navy bk ground */     
        line-height      : 12pt;
        margin           : 75px;  
      }
    </style>
  </head>
  <body>
  ";
  
  
    // list of prefix words to be added to beginning of URL name
      $prefix  = array(
        "Cool",
        "Fast",
        "Fire",
        "Fry",
        "Hot",
        "Maxi",
        "Quick",
        "Sugar",
        "Super",
        "Sweet",
        "Web",
        "X",
        "Xtra"
      );

    // list of suffix words to be added to end of URL name    
      $suffix = array(   
        "Dog",
        "Hut",
        "Kid",
        "Kit",
        "Man",
        "Power",
        "Pro",
        "Shop",
        "Shot",
        "Store",
        "Wiz",
        "World"
      );
    
  // process form, show prefix and suffix word combinations
  if (isset($_GET['name']) && $_GET['name'] != "") {
  
    $urlname = ucfirst($_GET['name']); // first letter of "name" to uppercase, test -> Test 
    ini_set('max_execution_time', 300);  // (5min) over ride default 30sec timeout error
    
    /* +----------------------------------+
       |          process PREFIX          |
       +----------------------------------+  */
    echo "<br><span style='color:#e33;'><h1>Prefix</h1></span>"; // word list title
    echo "<table>";   
    
    foreach($prefix as $item) {  // add each prefix and show

      echo "<tr><td>"$item . $urlname . "</td>";

      // check if .COM domain name exists
      $name = $item . $urlname . ".com";  
      $type = "ANY";   // domain type may be any of: A, MX, NS, SOA, PTR, CNAME, AAAA, A6, SRV, NAPTR, TXT or ANY.  
      
      if (checkdnsrr($name, $type)) {   
        echo "<td><span style='color:#e33;'>[.com]</span></td>"; // this is a registered domain
      } else {
        echo "<td><span style='color:#6fa;'>[.com]</span></td>"; // this domain doesn't exist!
      } // end of domain check    
      
      echo "</tr>";
      
    }   // end of each prefix

    echo "</table>";

    /* +----------------------------------+
       |          process SUFFIX          |
       +----------------------------------+  */    
    echo "<br><span style='color:#e33;'><h1>Suffix</h1></span>"; // word list title 
    echo "<table>";
    
    foreach($suffix as $item) {  // add each prefix and show
      
      echo "<tr><td>" . $urlname . $item . "</td>";

      // check if .COM domain name exists
      $name = $urlname . $item . ".com"; 
      $type = "ANY";   // domain type may be any of: A, MX, NS, SOA, PTR, CNAME, AAAA, A6, SRV, NAPTR, TXT or ANY.    
      
      if (checkdnsrr($name, $type)) {  
        echo "<td><span style='color:#e33;'>[.com]</span></td>"; // this is a registered domain
      } else {
        echo "<td><span style='color:#6fa;'>[.com]</span></td>"; // this domain doesn't exist!
      } // end of domain check  
      
      echo "</tr>";
      
    }   // end of each suffix

    echo "</table>";
    echo "<br><span style='color:#6fa;'>Green = name available</span><br>";

  }     // end of process form  
  
// +--------------------   show input form   ---------------------+
  echo "
  <form name='inputform' action=' " . $_SERVER['PHP_SELF'] . " ' method=\"get\">
    URL Name: <input type='text' width='100' maxlength='100' name='name' />
    <input type='submit' value='Submit' />
    <INPUT type='reset' />
    <br><br><b><span style='color:#e33;'>Be patient, this may take several minutes!</span></b>
  </form> 
  ";?>

 

Image 3

Going Further

In the original article I did not have the domain name registration check, but some readers objected. The disadvantage of doing a domain name check is that it takes at least one second per domain name. If you are checking 100 names, the domain check approaches two minutes to process.

Anyway, it is easy for a user to comment out the domain name check. It was also suggested that other extensions be checked such as .org, .biz, etc. It is obvious that the program would be to slow if this where done on a large number of names.

The goal of this article was to keep the subject material at the beginner level. There are no shortages of enhancements that could be made. For example, instead of having the program check domain name availability a button could be provided for the user to select. This would certainly resolve the long computation speed times.

However, to include the domain name check button would require an additional routine and printout. This would just about double the code size and most certainly intimidate a new programmer. Users are encouraged to add this feature if it is desirable. Perhaps in a future update I can show how this option could be implimented.

Conclusion

While I was developing this utility I submitted the form 15-20 times in a 2-3 hour period. I noticed that my domain availability requests started to be denied. I had to continue the following day. It appears that the domain name server was smart enough to see the large number of requests that I was making. So be aware that there may be some limits on the number of requests that can be made in a given amount of time.

I hope this helps you out!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionMy rating of 4 Pin
Bill_Hallahan18-Dec-13 14:07
Bill_Hallahan18-Dec-13 14:07 
AnswerRe: My rating of 4 Pin
Jan Zumwalt19-Dec-13 12:07
Jan Zumwalt19-Dec-13 12:07 
GeneralMy vote of 1 Pin
bbirajdar2-May-12 23:24
bbirajdar2-May-12 23:24 
QuestionNice demonstration of arrays and string concatenation Pin
bbirajdar2-May-12 23:23
bbirajdar2-May-12 23:23 
SuggestionNot much really Pin
L Viljoen1-May-12 23:16
professionalL Viljoen1-May-12 23:16 
AnswerRe: Not much really Pin
Jan Zumwalt2-May-12 18:30
Jan Zumwalt2-May-12 18:30 
GeneralMy vote of 1 Pin
Alberto Venditti1-May-12 10:51
Alberto Venditti1-May-12 10:51 
Very little more conceptual content over a "hello world" application.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.