[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 05-01-2007, 05:51 PM   #1 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
 
Join Date: Apr 2005
Location: Arizona
Posts: 3,644
285.00 NP$ (Donate)

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!
__________________

RegFee.info - Available Domain Names - NEW DESIGN!
DNWholesaler.com - Domains for Sale

<--- baby Rogan says: sorry for spelling/punctuation mistakes, daddy's feeding me
RegFee is offline  
Old 05-01-2007, 06:10 PM   #2 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

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, 08:57 PM   #3 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
 
Join Date: Apr 2005
Location: Arizona
Posts: 3,644
285.00 NP$ (Donate)

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?
__________________

RegFee.info - Available Domain Names - NEW DESIGN!
DNWholesaler.com - Domains for Sale

<--- baby Rogan says: sorry for spelling/punctuation mistakes, daddy's feeding me
RegFee is offline  
Old 05-02-2007, 10:16 AM   #4 (permalink)
NamePros Regular
 
abdussamad's Avatar
 
Join Date: Jul 2006
Location: Karachi
Posts: 708
94.60 NP$ (Donate)

abdussamad is just really niceabdussamad is just really niceabdussamad is just really niceabdussamad is just really nice


Quote:
Originally Posted by RegFee
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?
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 />
abdussamad is offline  
Old 05-02-2007, 10:55 AM   #5 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
 
Join Date: Apr 2005
Location: Arizona
Posts: 3,644
285.00 NP$ (Donate)

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.

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

PHP Code:

<?php

if (isset($_POST['stuff']))
{
    
$stuff = explode(" ", $_POST['stuff']);
    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!
__________________

RegFee.info - Available Domain Names - NEW DESIGN!
DNWholesaler.com - Domains for Sale

<--- baby Rogan says: sorry for spelling/punctuation mistakes, daddy's feeding me
RegFee is offline  
Old 05-02-2007, 11:11 AM   #6 (permalink)
NamePros Regular
 
monaco's Avatar
 
Join Date: Jul 2005
Location: Tucson, AZ
Posts: 695
314.80 NP$ (Donate)

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, 01:27 PM   #7 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
 
Join Date: Apr 2005
Location: Arizona
Posts: 3,644
285.00 NP$ (Donate)

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)
    {
        
$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>
          <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
__________________

RegFee.info - Available Domain Names - NEW DESIGN!
DNWholesaler.com - Domains for Sale

<--- baby Rogan says: sorry for spelling/punctuation mistakes, daddy's feeding me
RegFee is offline  
Old 05-02-2007, 02:26 PM   #8 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

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, 05:31 PM   #9 (permalink)
cef
NamePros Regular
 
Join Date: May 2004
Location: NYC
Posts: 236
76.50 NP$ (Donate)

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;
}

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)
    {
        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 05:33 PM. Reason: fixed underscore that should have been a dash
cef is offline  
Old 05-02-2007, 05:37 PM   #10 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
 
Join Date: Apr 2005
Location: Arizona
Posts: 3,644
285.00 NP$ (Donate)

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
Quote:
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);
        
//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);
Perfect!
__________________

RegFee.info - Available Domain Names - NEW DESIGN!
DNWholesaler.com - Domains for Sale

<--- baby Rogan says: sorry for spelling/punctuation mistakes, daddy's feeding me

Last edited by RegFee; 05-02-2007 at 05:42 PM.
RegFee is offline  
Old 05-02-2007, 10:00 PM   #11 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
 
Join Date: Apr 2005
Location: Arizona
Posts: 3,644
285.00 NP$ (Donate)

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?
__________________

RegFee.info - Available Domain Names - NEW DESIGN!
DNWholesaler.com - Domains for Sale

<--- baby Rogan says: sorry for spelling/punctuation mistakes, daddy's feeding me

Last edited by RegFee; 05-02-2007 at 10:20 PM.
RegFee is offline  
Old 05-03-2007, 03:39 AM   #12 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

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);
...
Dan is offline  
Old 05-03-2007, 11:55 AM   #13 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
 
Join Date: Apr 2005
Location: Arizona
Posts: 3,644
285.00 NP$ (Donate)

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']) ? '-' : '';
$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
__________________

RegFee.info - Available Domain Names - NEW DESIGN!
DNWholesaler.com - Domains for Sale

<--- baby Rogan says: sorry for spelling/punctuation mistakes, daddy's feeding me
RegFee is offline  
Old 05-03-2007, 01:17 PM   #14 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

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';
    
$dashes  = ($_POST['dashes']) ? '': "-";
    
$stuff   = strtolower($_POST['stuff']);
    
$minlen  = intval($_POST['minlength']);
    
$maxlen  = intval($_POST['maxlength']);
    
$ext     = $_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)
    {
        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, 08:19 PM   #15 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
 
Join Date: Apr 2005
Location: Arizona
Posts: 3,644
285.00 NP$ (Donate)

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/
__________________

RegFee.info - Available Domain Names - NEW DESIGN!
DNWholesaler.com - Domains for Sale

<--- baby Rogan says: sorry for spelling/punctuation mistakes, daddy's feeding me

Last edited by RegFee; 05-03-2007 at 11:27 PM.
RegFee is offline  
Old 05-05-2007, 03:07 AM   #16 (permalink)
cef
NamePros Regular
 
Join Date: May 2004
Location: NYC
Posts: 236
76.50 NP$ (Donate)

cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough

Animal Rescue
Quote:
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)
cef is offline  
Old 05-05-2007, 10:09 AM   #17 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
 
Join Date: Apr 2005
Location: Arizona
Posts: 3,644
285.00 NP$ (Donate)

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
Quote:
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)

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
__________________

RegFee.info - Available Domain Names - NEW DESIGN!
DNWholesaler.com - Domains for Sale

<--- baby Rogan says: sorry for spelling/punctuation mistakes, daddy's feeding me
RegFee is offline  
Old 05-05-2007, 11:19 AM   #18 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

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, 11:24 AM   #19 (permalink)
cef
NamePros Regular
 
Join Date: May 2004
Location: NYC
Posts: 236
76.50 NP$ (Donate)

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
$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)) ?
            
' 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 12:05 PM.
cef is offline  
Old 05-05-2007, 05:50 PM   #20 (permalink)
DNOA Certified Seller
 
RegFee's Avatar
 
Join Date: Apr 2005
Location: Arizona
Posts: 3,644
285.00 NP$ (Donate)

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.
__________________

RegFee.info - Available Domain Names - NEW DESIGN!
DNWholesaler.com - Domains for Sale

<--- baby Rogan says: sorry for spelling/punctuation mistakes, daddy's feeding me
RegFee is offline  
Old 05-05-2007, 10:38 PM   #21 (permalink)
cef
NamePros Regular
 
Join Date: May 2004
Location: NYC
Posts: 236
76.50 NP$ (Donate)

cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough

Animal Rescue
Quote:
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)

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 03:32 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85