NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Looking for a program that will...

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-01-2007, 06:51 PM THREAD STARTER               #1 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
Join Date: Apr 2005
Location: Arizona
Posts: 3,680
RegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond repute
 


Third World Education Third World Education Save The Children Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health

Looking for a program that will...


I'm looking for a program that will take a bunch of randomly spaced text and place all of the words into separate lines.

for example:

asdf asdfasdf asdfasdfasdf.

Will be cleaned into:
asdf
asdfasdf
asdfasdfasdf

Thanks!
__________________
Nombrex.com
RegFee is offline  
Old 05-01-2007, 07:10 PM   #2 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
PHP Code:
<?php

if (isset($_POST['stuff']))
{
    
$stuff explode(" "$_POST['stuff']);
    foreach (
$stuff as $thing)
    {
        echo 
trim($thing) . "<br />";
    }
    echo 
"<br /><br />";
}

?>
<form action="" method="post">
    <input type="text" name="stuff" style="width: 300px;" /><br />
    <input type="submit" value="Submit" />
</form>
Dan is offline  
Old 05-01-2007, 09:57 PM THREAD STARTER               #3 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
Join Date: Apr 2005
Location: Arizona
Posts: 3,680
RegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond repute
 


Third World Education Third World Education Save The Children Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health
Thanks Dan. I put it here:

http://www.regfee.info/php/clean.php

NP won't let me rep you anymore, I must've liked something else you did

How would I go about modifying this code to use a large textbox, so I could, say, edit->select all and paste random stuff into it, and each word will be put on a new line?
__________________
Nombrex.com
RegFee is offline  
Old 05-02-2007, 11:16 AM   #4 (permalink)
NamePros Regular
 
abdussamad's Avatar
Join Date: Jul 2006
Location: Karachi
Posts: 791
abdussamad is a glorious beacon of lightabdussamad is a glorious beacon of lightabdussamad is a glorious beacon of lightabdussamad is a glorious beacon of lightabdussamad is a glorious beacon of light
 



Originally Posted by RegFee
Thanks Dan. I put it here:
????: NamePros.com http://www.namepros.com/programming/323152-looking-for-a-program-that-will.html

http://www.regfee.info/php/clean.php

NP won't let me rep you anymore, I must've liked something else you did

How would I go about modifying this code to use a large textbox, so I could, say, edit->select all and paste random stuff into it, and each word will be put on a new line?
Just replace this line in Dan's code:

Code:
 <input type="text" name="stuff" style="width: 300px;" /><br />
with this:

Code:
<textarea cols="40" rows="10" name="stuff"></textarea><br />
__________________
site unblocker - Computer Hardware
abdussamad is offline  
Old 05-02-2007, 11:55 AM THREAD STARTER               #5 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
Join Date: Apr 2005
Location: Arizona
Posts: 3,680
RegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond repute
 


Third World Education Third World Education Save The Children Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health
Thanks for moving it to the programming forum, mods. I didn't place it there at first because I was thinking an actual program might exist that does this, but PHP works just fine.

Thanks abdussamad, I had tried this already and for some reason, it doesn't always work for huge jumbled messes of words.
????: NamePros.com http://www.namepros.com/showthread.php?t=323152

Here is the code, modified to clean out unnecessary characters:

PHP Code:

<?php

if (isset($_POST['stuff']))
{
    
$stuff explode(" "$_POST['stuff']);
????: NamePros.com http://www.namepros.com/showthread.php?t=323152
    foreach (
$stuff as $thing)
    {
        echo 
trim(ereg_replace("[^A-Za-z0-9]"""$thing)) . "<br />";
    }
    echo 
"<br /><br />";
}

?>
<form action="" method="post">
    <textarea cols="40" rows="10" name="stuff"></textarea><br />
    <input type="submit" value="Submit" />
</form>
Uploaded here:
http://www.regfee.info/php/clean.php

If I input

Quote:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas vestibulum, nulla a rhoncus malesuada, nunc mauris sodales lectus, et ornare lectus eros sit amet massa.
I get
Quote:
Lorem
ipsum
dolor
sit
amet
consectetuer
adipiscing
elit
Maecenas
vestibulum
nulla
a
rhoncus
malesuada
nunc
mauris
sodales
lectus
et
ornare
lectus
eros
sit
amet
massa
Which is what I want.

However, if I copy and paste the entire front page of Namepros, for example, I get things like this:
Quote:
OutDomain
ServicesNP
Domain
RegistrationNP
Domain
ManagementBuy
Domain
CreditDomain
ToolsWHOIS
Lookup

and

2007
Jelsoft
Enterprises
LtdSearch
Engine
Friendly
URLs
by
vBSEO
240
Any idea why these two inputs would be treated any differently by the explode function?

Thanks again!
__________________
Nombrex.com
RegFee is offline  
Old 05-02-2007, 12:11 PM   #6 (permalink)
NamePros Regular
 
monaco's Avatar
Join Date: Jul 2005
Location: Tucson, AZ
Posts: 689
monaco will become famous soon enough
 



One probably has more than 1 space. Consider using a regex-based explode that will break on whitespace instead of just spaces.
__________________
My Website | My Blog
monaco is offline  
Old 05-02-2007, 02:27 PM THREAD STARTER               #7 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
Join Date: Apr 2005
Location: Arizona
Posts: 3,680
RegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond repute
 


Third World Education Third World Education Save The Children Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health

Thanks


Thanks manaco and everyone else.

http://www.regfee.info/php/clean.php will now (hopefully) clean a big huge mess of words into words of specified length and will even tack on an extension if you'd like.

Here's the code (still needs to be cleaned up, but since I'm just starting out, I like to keep everything as unoptimized as possible to minimize my own confusion.)

PHP Code:
<?php
$ext 
$_POST['ext'];
$minlength $_POST['minlength'];
$maxlength $_POST['maxlength'];
if (
$maxlength $minlength)
{
    echo 
"The maximum length cannot be smaller than the minimum.<br />";
    
$_POST['stuff'] = null;
}

if (isset(
$_POST['stuff']))
{
    
$stuff explode(" "$_POST['stuff']);
    foreach (
$stuff as $thing
    {
????: NamePros.com http://www.namepros.com/showthread.php?t=323152
        
$thing ereg_replace("[^A-Za-z\n\s]"" "$thing);
        
$thing2 explode(" "$thing);
        foreach (
$thing2 as $word)
        {
             
$length strlen(trim($word));
            if (
$length >= $minlength && $length <= $maxlength)
            {
                echo 
$word;
                if (
$ext != "none"){ echo "." $ext;}
                echo 
"<br />";
            }
        }
    }
    echo 
"<br /><br />";
}
else {echo 
"Enter text into the box below:";}
?>
<form action="" method="post">
    <textarea cols="40" rows="10" name="stuff"></textarea><br />
    Min Length:
    <select name="minlength">
        <option selected value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
        <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
        <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
        <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
          
    </select> 
    Max Length:
    <select name="maxlength">
        <option selected value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
        <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
        <option value="11">11</option>
????: NamePros.com http://www.namepros.com/showthread.php?t=323152
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
        <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
    </select>
      <br />
    Choose an extension:
    <select name="ext" size="-1">
        <option selected value="none">None</option>        
        <option value="com">.com</option>
        <option value="net">.net</option>
        <option value="org">.org</option>
        <option value="mobi">.mobi</option>
        <option value="biz">.biz</option>
        <option value="info">.info</option>
        <option value="us">.us</option>
        <option value="tv">.tv</option>
        <option value="cc">.cc</option>
        <option value="bz">.bz</option>
    </select>
    <br />
    <input type="submit" value="Submit" />
</form>

Please test the script out if you get a chance and recommend any optimizations.

Dan, I would like to place this tool on regfee.info, if you don't mind. Also if any of you would like me to place a link to one of your sites at the bottom of the script, just let me know.

Thanks!
-Jorge
__________________
Nombrex.com
RegFee is offline  
Old 05-02-2007, 03:26 PM   #8 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
I don't mind if you use it and I don't need any links.

The problem was with new lines. You could explode by new lines first, then loop through those and explode by spaces.
Dan is offline  
Old 05-02-2007, 06:31 PM   #9 (permalink)
cef
NamePros Regular
Join Date: May 2004
Location: NYC
Posts: 236
cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough
 


Animal Rescue
Monaco's right; a regular expression match is far simpler, and can also include the min/max length checking.

Here's a modification of your php code from above (I didn't copy the html below it). The code also includes a check for two additional $_POST variables: 'numbers' and 'dashes', which modify the search filter to also include numbers and/or dashes.

You can add checkboxes for this (if you'd like) to your html form.

PHP Code:
<?php
// filter numeric input
$minlength intval($_POST['minlength']);
$maxlength intval($_POST['maxlength']);

// filter and format the extention if there is one
$ext = ($_POST['ext'] == 'none') ? '' '.' htmlentities($_POST['ext']);

// see if the user wants dashes and/or numbers too
$dashes = isset($_POST['dashes']) ? '-' '';
$numbers = isset($_POST['numbers']) ? '0-9' '';
    
if (
$maxlength $minlength)
{
    echo 
"The maximum length cannot be smaller than the minimum.<br />";
    
$_POST['stuff'] = null;
????: NamePros.com http://www.namepros.com/showthread.php?t=323152
}

if (isset(
$_POST['stuff']))
{
    
// construct our regular expression string to get only words with
    // valid characters and of the min/max length
    
$preg '/[A-Za-z' $dashes $numbers ']{'$minlength ',' $maxlength '}/m';

    
// now match everything in the input
    
$stuff = array();
    
preg_match_all($preg,$_POST['stuff'],$stuff);

    
// process results only if we have them
    
if (count($stuff) != 0)
????: NamePros.com http://www.namepros.com/showthread.php?t=323152
    {
        foreach (
$stuff as $word)
            echo 
$word$ext'<br />';
        echo 
'<br /><br />';
    }
}
else {echo 
'Enter text into the box below:';}
?>
Last edited by cef; 05-02-2007 at 06:33 PM. Reason: fixed underscore that should have been a dash
cef is offline  
Old 05-02-2007, 06:37 PM THREAD STARTER               #10 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
Join Date: Apr 2005
Location: Arizona
Posts: 3,680
RegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond repute
 


Third World Education Third World Education Save The Children Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health
Originally Posted by Dan
I don't mind if you use it and I don't need any links.

The problem was with new lines. You could explode by new lines first, then loop through those and explode by spaces.
Thanks Dan!

This is how I like to learn, by diving right into code. I try to crack open a beginner's php book, and I'm bored within 2 seconds.

Your suggestion worked:

PHP Code:



    <?php
//Pull data from form input    
$ext $_POST['ext'];
$minlength $_POST['minlength'];
$maxlength $_POST['maxlength'];
//Check if invalid mins and maxes were used
if ($maxlength $minlength)
{
    echo 
"The maximum length cannot be smaller than the minimum.<br />";
    
$_POST['stuff'] = null;
}

//If form is submitted, run cleaning & generating code.    
if (isset($_POST['stuff']))
{
//Create an array $stuff with each line of text
  
$stuff explode("\n"$_POST['stuff']); 

//Loop through array
  
foreach ($stuff as $thing
    {
        
//remove unneeded characters
        
$thing ereg_replace("[^A-Za-z\n\s]"" "$thing);
????: NamePros.com http://www.namepros.com/showthread.php?t=323152
        
//Create a new array $thing with each word of text
        
$thing explode(" "$thing); 
        
//Loop through $thing array
        
foreach ($thing as $word)
        { 
         
//get string length and only display if meets criteria
         
$length strlen($word);
            if (
$length >= $minlength && $length <= $maxlength)
            {
                echo 
$word;
                if (
$ext != "none"){ echo "." $ext;}
                echo 
"<br />";
            }
        }
    }
    
    echo 
"<br /><br />";
}


    
    
?>
<form action="" method="post">
    <textarea cols="40" rows="10" name="stuff"></textarea><br />
    Min Length:
    <select name="minlength">
        <option selected value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
        <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
        <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
        <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
          
    </select> 
    Max Length:
    <select name="maxlength">
        <option selected value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
        <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
        <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
        <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
    </select>
      <br />
    Choose an extension:
    <select name="ext" size="-1">
        <option selected value="none">None</option>        
        <option value="com">.com</option>
        <option value="net">.net</option>
        <option value="org">.org</option>
        <option value="mobi">.mobi</option>
        <option value="biz">.biz</option>
        <option value="info">.info</option>
        <option value="us">.us</option>
        <option value="tv">.tv</option>
        <option value="cc">.cc</option>
        <option value="bz">.bz</option>
    </select>
    <br />
    <input type="submit" value="Submit" />
</form>

uploaded to http://www.regfee.info/php/fasterclean.php

Now I just need to display the results in a textarea for easier copy/pasting, and add a counter to display the number of generated domains.

I was thinking of making it check for duplicates as well, but won't that involve either huge arrays or using a db?

EDIT: Nevermind, right when I posted the question about duplicates, I realized I was being an idiot. I'm already running everything through huge arrays, so why not just use:
PHP Code:
$thing array_unique($thing); 
????: NamePros.com http://www.namepros.com/showthread.php?t=323152
Perfect!
__________________
Nombrex.com
Last edited by RegFee; 05-02-2007 at 06:42 PM.
RegFee is offline  
Old 05-02-2007, 11:00 PM THREAD STARTER               #11 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
Join Date: Apr 2005
Location: Arizona
Posts: 3,680
RegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond repute
 


Third World Education Third World Education Save The Children Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health
Never mind, not so perfect after all. It's not removing duplicates, and since I've tried every variation of code I code find that mimics the unique array function (including one that checked if each value matched a new array and then added the value to the array if it didn't), but all of them keep failing to remove the duplicates. I have a strong feeling it is due to whitespace again, but I thought I took care of that with the ereg.

Cef, I didn't even see your response! I tried it out, but it is just showing "array". I was reading up on the trim function, and it said if you try to trim an array, it will just display the word array, is this a similar problem?
__________________
Nombrex.com
Last edited by RegFee; 05-02-2007 at 11:20 PM.
RegFee is offline  
Old 05-03-2007, 04:39 AM   #12 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
PHP Code:
...
        foreach (
$thing as $word)
        {
                
$word trim($word);
????: NamePros.com http://www.namepros.com/showthread.php?t=323152
 ... 
Dan is offline  
Old 05-03-2007, 12:55 PM THREAD STARTER               #13 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
Join Date: Apr 2005
Location: Arizona
Posts: 3,680
RegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond repute
 


Third World Education Third World Education Save The Children Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health
I figured out my mistake. I was trying to remove duplicates from the miniature arrays created with each loop, but not from the final product. I ended up making it so each word that meets the length requirements is put into a new array, then that new array is finally stripped of duplicates.

I then ran into the problem of different cases, and for some reason the array key case change wouldn't work, so I just did a strtolower($word) on the words before putting them in the new array.

My issue NOW is getting the new dashes and numbers thing to work with ereg, since I couldn't get preg to work.

PHP Code:
...

$dashes = isset($_POST['dashes']) ? '-' '';
????: NamePros.com http://www.namepros.com/showthread.php?t=323152
$numbers = isset($_POST['numbers']) ? '0-9' '';

...

$thing ereg_replace("[^A-Za-z]"" "$thing);

//why can't I just do this?

$thing ereg_replace("[^A-Za-z".$numbers.$dashes."]"" "$thing); 
Almost there
Jorge
__________________
Nombrex.com
RegFee is offline  
Old 05-03-2007, 02:17 PM   #14 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
PHP Code:
<?php

if (isset($_POST['stuff']))
{
    
$numbers = ($_POST['numbers']) ? '''0-9';
????: NamePros.com http://www.namepros.com/showthread.php?t=323152
    
$dashes  = ($_POST['dashes']) ? ''"-";
    
$stuff   strtolower($_POST['stuff']);
    
$minlen  intval($_POST['minlength']);
    
$maxlen  intval($_POST['maxlength']);
    
$ext     $_POST['ext'];
????: NamePros.com http://www.namepros.com/showthread.php?t=323152
    
$preg    '/\b[a-z'.$numbers.$dashes.']{'.$minlen.','.$maxlen.'}\b/si';
    
preg_match_all($preg$stuff$matches);
    
$array   array_unique($matches[0]);
    foreach (
$array as $word)
    {
        if (
$word != "")
        {
            if (
$ext == "none") echo "$word<br />\n";
            else echo 
"$word.$ext<br />\n";
        }
    }    
}

?>
<form action="" method="post">
    <textarea cols="40" rows="10" name="stuff"></textarea><br />
    Min Length:
    <select name="minlength">
        <option selected value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
        <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
        <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
        <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
          
    </select> 
    Max Length:
    <select name="maxlength">
        <option selected value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
        <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
        <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
        <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
    </select>
    <br />
    Choose an extension:
    <select name="ext" size="-1">
        <option selected value="none">None</option>        
        <option value="com">.com</option>
        <option value="net">.net</option>
        <option value="org">.org</option>
        <option value="mobi">.mobi</option>
        <option value="biz">.biz</option>
        <option value="info">.info</option>
        <option value="us">.us</option>
        <option value="tv">.tv</option>
        <option value="cc">.cc</option>
        <option value="bz">.bz</option>
    </select>
    <br />
    Exclude:
    <input type="checkbox" name="numbers" /> Numbers <input type="checkbox" name="dashes" /> Dashes</br />
    <br />
    <input type="submit" value="Submit" />
</form>

Dan is offline  
Old 05-03-2007, 09:19 PM THREAD STARTER               #15 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
Join Date: Apr 2005
Location: Arizona
Posts: 3,680
RegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond repute
 


Third World Education Third World Education Save The Children Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health
Beautiful code, works like a charm. To whom to I make the check out to?


Update:
I got it to work with wordpress (frustrating).


http://www.regfee.info/domain-name-generator-tool/
__________________
Nombrex.com
Last edited by RegFee; 05-04-2007 at 12:27 AM.
RegFee is offline  
Old 05-05-2007, 04:07 AM   #16 (permalink)
cef
NamePros Regular
Join Date: May 2004
Location: NYC
Posts: 236
cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough
 


Animal Rescue
Originally Posted by RegFee
Cef, I didn't even see your response! I tried it out, but it is just showing "array". I was reading up on the trim function, and it said if you try to trim an array, it will just display the word array, is this a similar problem?
Not sure which of all the above you went with, but for posterity, here's the fix for the typo in the code I posted.

Change this:

PHP Code:
        foreach ($stuff as $word
To this:

PHP Code:
        foreach ($stuff[0] as $word
????: NamePros.com http://www.namepros.com/showthread.php?t=323152
cef is offline  
Old 05-05-2007, 11:09 AM THREAD STARTER               #17 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
Join Date: Apr 2005
Location: Arizona
Posts: 3,680
RegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond repute
 


Third World Education Third World Education Save The Children Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health
Originally Posted by cef
Not sure which of all the above you went with, but for posterity, here's the fix for the typo in the code I posted.

Change this:

PHP Code:
        foreach ($stuff as $word
To this:

PHP Code:
        foreach ($stuff[0] as $word
????: NamePros.com http://www.namepros.com/showthread.php?t=323152

Do you mind if I ask why it is necessary to add the [0] key in there? I already declared $stuff as an array, to me this seems like this would just be saying "make the first key of the array a word", not "make each key of the array a word."

Thanks,
Jorge
__________________
Nombrex.com
RegFee is offline  
Old 05-05-2007, 12:19 PM   #18 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
When you do preg_match_all, it gives you two arrays (inside the result).
I forget what goes into each, but it's like the matches for (.*)? or whatever and then the full matched reg exp.
Dan is offline  
Old 05-05-2007, 12:24 PM   #19 (permalink)
cef
NamePros Regular
Join Date: May 2004
Location: NYC
Posts: 236
cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough
 


Animal Rescue
Heh, as I was typing a response, Dan just posted!

When I wrote and tested the code I used different variable names, and then refactored them into what I pasted into my response. I guess I got a little overzealous when replacing and also removed the '[0]' part, which is why it was missing here but worked when I tested it.

Here's a new version, based on the last version (posted by Dan), with a couple of minor optimizations, a check and correction for min > max, and most importantly...sticky form values(!)

The form now remembers and displays all setting from the last call instead of resetting everything.

To do this, the code now generates the min/max size lists and extention list programmatically, so that it can easily assign the "checked" attribute to the relevant list items.

Also, this makes it easier to add or remove extentions, or change the min/max sizes.

Tested and works

PHP Code:
<?php

if (isset($_POST['stuff']))
{
    
$numbers = ($_POST['numbers']) ? '''0-9';
    
$dashes  = ($_POST['dashes']) ? ''"-";
    
$stuff   strtolower($_POST['stuff']);
    
$minlen  intval($_POST['minlength']);
    
$maxlen  intval($_POST['maxlength']);
    if (
$minlen $maxlen$maxlen $minlen;
    
$ext     = ($_POST['ext'] !== 'none') ? '.' $_POST['ext'] : '';
    
$preg    '/\b[a-z'.$numbers.$dashes.']{'.$minlen.','.$maxlen.'}\b/si';
    
preg_match_all($preg$stuff$matches);
    
$array   array_unique($matches[0]);
    foreach (
$array as $word)
        echo 
$word$ext'<br />';
}
else
{
    
// set defaults for the form controls
    
$numbers '0-9';
    
$dashes '-';
    
$stuff '';
    
$minlen 3;
    
$maxlen 3;
    
$ext '';
}

// available domain extentions
????: NamePros.com http://www.namepros.com/showthread.php?t=323152
$extentions = array(
    
'none',
    
'com',
    
'net',
    
'org',
    
'mobi',
    
'biz',
    
'info',
    
'us',
    
'tv',
    
'cc',
    
'bz'
);

// build a select list of sizes with a selected entry
function build_size_list($min,$max,$selected)
{
    for (
$i=$min$i <= $max$i++)
       echo 
'<option '$i == $selected ' selected="selected" ' '''value="'$i'">'$i "</option>\n"
}

// build the extension list with a selected entry
function build_extention_list($extention_array,$selected)
{
    foreach(
$extention_array as $extention)
       echo 
'<option '
            (
$extention === 'none' && $selected === '') || ($selected === ('.' $extention)) ? 
????: NamePros.com http://www.namepros.com/showthread.php?t=323152
            
' selected="selected" ' '''value="'$extention'">'$extention "</option>\n"
}

?>
<form action="" method="post">
    <textarea cols="40" rows="10" name="stuff"><?php echo htmlentities($stuff); ?></textarea><br />
    Min Length:
    <select name="minlength">
        <?php build_size_list(3,18,$minlen); ?>
    </select> 
    Max Length:
    <select name="maxlength">
        <?php build_size_list(3,18,$maxlen); ?>
    </select>
    <br />
    Choose an extension:
    <select name="ext" size="-1">
        <?php build_extention_list($extentions,$ext); ?>
    </select>
    <br />
    Exclude:
    <input type="checkbox" name="numbers" <?php echo $numbers == '' ' checked="checked" ' '';  ?> /> Numbers 
    <input type="checkbox" name="dashes" <?php echo $dashes == ''  ' checked="checked" ' '';  ?> /> Dashes</br />
    <br />
    <input type="submit" value="Submit" />
</form>
Last edited by cef; 05-05-2007 at 01:05 PM.
cef is offline  
Old 05-05-2007, 06:50 PM THREAD STARTER               #20 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
Join Date: Apr 2005
Location: Arizona
Posts: 3,680
RegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond reputeRegFee has a reputation beyond repute
 


Third World Education Third World Education Save The Children Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health Baby Health
Thanks guys!
Cef, my next goal was to make the form remember the settings. I didn't think to make functions to do it, definitely a lot cleaner than I would've made it. Of course, now I have to think of something else to learn how to do, thanks

Your guys' help has been invaluable. Maybe in a year I'll be able to help people who are just starting out as much as you've helped me.
__________________
Nombrex.com
RegFee is offline  
Old 05-05-2007, 11:38 PM   #21 (permalink)
cef
NamePros Regular
Join Date: May 2004
Location: NYC
Posts: 236
cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough
 


Animal Rescue
Originally Posted by RegFee
Thanks guys!
Cef, my next goal was to make the form remember the settings. I didn't think to make functions to do it, definitely a lot cleaner than I would've made it. Of course, now I have to think of something else to learn how to do, thanks

Your guys' help has been invaluable. Maybe in a year I'll be able to help people who are just starting out as much as you've helped me.
Ooops, sorry, I was on a roll and having fun. But if you still want to do it yourself, don't look at it! And I revoke all rights to use! (kidding, kidding)
????: NamePros.com http://www.namepros.com/showthread.php?t=323152

Things to add...whois lookups for each name so that the user knows which is available for registration? Maybe some kind of alternative name suggester (a namespinner type of thing)? Just some random thoughts.

Also, error checking could be a little better. Verify that min/max are in the correct bounds, verify that the extention is valid. These are a two-minute fix, but I'll leave it to you
cef is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 04:03 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger