Jump to content

creating url list with http_build_url


etrader

Recommended Posts

I made a url generator.

http://dynaindex.com/keyword-navigation

What this does is will accept up to 10 keywords and mix them into the most common domains up to 4 keyword positions. Then I have it check alive and dead, display some info and a thumb if alive.

 

Although I made it do a lot more than just make them there, it started off a word generator, then a domain generator and so on.

But i do have other stuff that can surely do what you need.

 

I will say it took a pretty long time to accomplish, if needed any help just shoot me a message and I'll see what I can do.

 

Here is what you can do to get what you need done.

 

The text file with words include as an array and variables, can do a count so you know how many are making.

 

Then for each word in the array you echo it or make that a new array to save to database or text files, not sure what doing with them.

So with a for ++ using count of words array, append your http://example.com/ to the front. If I got a bit of time I can write something simple up. I gotta do a few things first.

Link to comment
Share on other sites

ok, so here is what I got. I made the sample array of words can delete.

Replace the text file names to what you want.

 

A brief description:

Get array of words from a text file, sort them in order, I echo so can see the results, create a new url_array of the results, print the array info, implode the array with line break and insert into a text file.

 

I suppose if need anything different can easily modify it.

<?php
//generate urls from words array so can see it work
/*$words_array = array("one","two","three","four","five","six","seven","eight","nine","word8","word3","word4","word9","anotherword","hello","funny","great","cool","nice");
*/


$my_word_file = "wordfile1.txt";
$write_file = "urls1.txt";

//getting from text file section
if (file_exists($my_word_file)) {
$words_array = file($my_word_file);

asort($words_array);//sort the array
foreach ($words_array as $word) {
$word = trim($word);
echo "http://example.com/$word<br />";
$url_array[] = "http://example.com/$word";
}

//see array values from $url_array
print_r($url_array);

//write to a text file
$write = fopen($write_file, 'w');
$new_urls = implode("\r\n",$url_array);
fputs($write, $new_urls);
fclose($write);

} else {
echo "File does not exist";
}
?>

Link to comment
Share on other sites

Thanks QuickOldCar, it is really amazing, exactly what I needed. I used echo instead of print_r, as I wanted to create hyperlink and displaying array is not needed.

 

However, could you please tell me how I can display randomly e.g., 5 urls when the code is run each time.

 

Thanks again :)

Link to comment
Share on other sites

If you are getting these values from a database, you can add this to end of the select statement.

 

order by rand() LIMIT 5

 

But if still doing from text like I think you are....

The easiest way  found to get random results from an array is

shuffle($words_array);

 

If doing random then no need to sort the array, so remove this.

asort($words_array);

 

Here's a simple way I came up with.

Is so many ways to do this.

 

<?php
$words_array = array("one","two","three","four","five","six","seven","eight","nine","word8","word3","word4","word9","anotherword","hello","funny","great","cool","nice");

shuffle($words_array);
$i = 0;
foreach ($words_array as $words => $word) {
$word = trim($word);
echo "http://example.com/$word<br />";
    if (++$i == 5) break;
}

?>

Link to comment
Share on other sites

This fine for you?

 

<?php
$titles_array = array("one","two","three","four","five","six","seven","eight","nine","word8","word3","word4","word9","anotherword","hello","funny","great","cool","nice");

shuffle($titles_array);
$i = 0;
foreach ($titles_array as $titles => $title) {
$title = trim($title);
$title = "http://example.com/$title";
$link = "<a href='$title'>$title</a>";
echo "$link<br />";
    if (++$i == 5) break;
}

?>

Link to comment
Share on other sites

Maybe would like to show your title and not the full url.

 

<?php
$titles_array = array("one","two","three","four","five","six","seven","eight","nine","word8","word3","word4","word9","anotherword","hello","funny","great","cool","nice");

shuffle($titles_array);
$i = 0;
foreach ($titles_array as $titles => $title) {
$title = trim($title);
$make_link = "http://example.com/$title";
$link = "<a href='$make_link'>$title</a>";
echo "$link<br />";
    if (++$i == 5) break;
}

?>

Link to comment
Share on other sites

Absolutely perfect! This is exactly what I needed. Thanks a million  8)

 

Let me ask another question by my curiosity. How to put the results in an XML (to create RSS) as

<item>
<title>Title of an item</title>
<link>http://example.com/item/123</link>
<guid>http://example.com/item/123</guid>
<pubDate>Mon, 12 Sep 2005 18:37:00 GMT</pubDate>
</item>

 

Link to comment
Share on other sites

Sorry for many questions, but I really liked this amazing solution. In the case of

<?php
$titles_array = array("one","two","three","four","five","six","seven","eight","nine","word8","word3","word4","word9","anotherword","hello","funny","great","cool","nice");

shuffle($titles_array);
$i = 0;
foreach ($titles_array as $titles => $title) {
$title = trim($title);
$make_link = "http://example.com/$title";
$link = "<a href='$make_link'>$title</a>";
echo "$link<br />";
    if (++$i == 5) break;
}

?>

 

How it is possible to define a list of urls too. I mean having an array file containing

http://example1.com

http://example2.com

http://example3.com

 

and make links randomly by the urls and words  ::)

Link to comment
Share on other sites

This is a help forum really, not a do it for you.

The people here are to assist in the code you have and find errors.

 

I don't mind helping a little, or even sometimes more, but your making this into a complete advanced script for yourself without giving effort it seems.

 

I think you need to learn php at least a little.

http://php.net/manual/en/index.php

 

Or can visit the freelance section.

http://www.phpfreaks.com/forums/php-freelancing/

Link to comment
Share on other sites

Because this could benefit others and also is an interest of mine.

 

I had some time so went ahead and did the create random url's, tld's and also the words.

But I will say I'll do nothing more to this as this should be able to get done what you needed, if not start trying to make the changes you need to it.

 

remove comment for sort, array_unique if you need that.

comment the for line to see all results or change the number.

 

Good luck with it.

 

<?php
$domain_array = array("myspace","digg","google","phpfreaks","php","classic","tvcountdown","eight","nine","music","tv","people","game","poems","forum","funny","great","cool","nice");

//is about 500 tld and sld's that exist
$tld_array = array("com","net","org","biz","info","edu","mobi","co.uk");

$title_array = array("one","two","three","four","five","six","seven","eight","nine","word8","word3","word4","word9","anotherword","hello","funny","great","cool","nice");

shuffle($domain_array);
shuffle($title_array);
shuffle($tld_array);
$i = 0;
foreach ($domain_array as $domain) {
$domain = trim($domain);

foreach ($title_array as $title) {
$title = trim($title);

foreach ($tld_array as $tld) {
$tlds = trim($tld);

$links[] = "$domain.$tlds/$title";
  
}
}
}
shuffle($links);//shuffle random
//sort($links);//sort in order
//array_unique($links);//remove any duplicates
foreach ($links as $make_link){
$make_link = "http://$make_link";
$link = "<a href='$make_link'>$make_link</a>";
echo "$link<br />";
if (++$i == 5) break;//if comment this line or set number higher will see more results
}
?>

 

As for the xml, look into making an rss feed with php, is plenty of tutorials.

It would be best to make a new post so others can help and see what you needed.

Link to comment
Share on other sites

This is so kind of you. Actually, I made some efforts to modify the code. My problem was to use two 'foreach'. As you see, when we use

foreach ($titles_array as $titles => $title)

, we have the chance to use $title for making the url. But when using

foreach ($links as $make_link)

, the $title disappears and cannot be used for the link title. The problem is that we cannot have two variables, $links (as a mixture of initial variables: $domain, $tld, and $title) and $title for making the hyperlink.

Link to comment
Share on other sites

Version using title showing instead of the link.

 

<?php
$domain_array = array("myspace","digg","google","phpfreaks","php","classic","tvcountdown","eight","nine","word8","word3","people","word9","anotherdomain","hello","funny","great","cool","nice");

//is about 500 tld and sld's that exist
$tld_array = array("com","net","org","biz","info","edu","mobi","co.uk");

$title_array = array("one","two","three","four","five","six","seven","eight","nine","word8","word3","word4","word9","anotherword","hello","funny","great","cool","nice");

shuffle($domain_array);
shuffle($title_array);
shuffle($tld_array);
$i = 0;
foreach ($domain_array as $domain) {
$domain = trim($domain);

foreach ($title_array as $title) {
$title = trim($title);

foreach ($tld_array as $tld) {
$tlds = trim($tld);

$links[] = "<a href='http://$domain.$tlds/$title'>$title</a>";
  
}
}
}
shuffle($links);//shuffle random
//sort($links);//sort in order
//array_unique($links);//remove any duplicates
foreach ($links as $link){
echo "$link<br />";
if (++$i == 5) break;//if comment this line or set number higher will see more results
}
?>

Link to comment
Share on other sites

That's what makes this interesting to me and keep doing it. The challenge.

 

Is multiple ways to accomplish the same goal, sometimes have to be creative about it.

Some ways may do the job but either slow or undesired results, so try a different way.

 

So it's finally what needed and we can move on?

Link to comment
Share on other sites

I have a technical question: in the last code, we process the arrays in three foreach commands to process, then we randomly catch 5 of them and display. Imagine that the arrays are too long come from large txt files (e.g. 1GB). Does this overload the CPU usage?

Link to comment
Share on other sites

Grabbing many 1 gig files a lot certainly is not good.

When reading from a text file it must read the entire contents.

 

You should generate these and save them into a database for reuse.

This is why databases were made. It's more efficient than flat files.

 

Another possible option is to load the words into a database in fields, and grab just a random 5 each from those.

 

 

 

Link to comment
Share on other sites

Just out of curiosity; in the first version where the link is generated for each random word as

<?php
$titles_array = array("one","two","three","four","five","six","seven","eight","nine","word8","word3","word4","word9","anotherword","hello","funny","great","cool","nice");

shuffle($titles_array);
$i = 0;
foreach ($titles_array as $titles => $title) {
$title = trim($title);
$make_link = "http://example.com/$title";
$link = "<a href='$make_link'>$title</a>";
echo "$link<br />";
    if (++$i == 5) break;
}

?>

we have the same CPU issue? I mean that php reads throughout the file to find a random word?

Link to comment
Share on other sites

You may need to think out a system for yourself that works best for your situation.

 

Maybe explain what exactly doing as a whole in this project, what the exact purpose of generating all these url's are and when they are called upon and how often.

 

As for your question, if the server doesn't have to do as much work is always better.

If you are pulling a 1 gig+ file each time, I would think of alternate ways of doing this, like run it once and save groups of five into arrays or like i said just start saving each into a mysql database structure for future use. 3 fields for words for each part and just pulling a random 5 from that would work also.

 

I could think of one way for you of doing this the same as you have with less usage, lets say you have a folder named like randoms. Then inside the folder 3 more folders named  urls,titles,tld, in each of those folders start naming text files as 1.txt, 2.txt, 3.txt, 4.txt and so on. Basically splitting up your huge 1 gig+ lists into smaller chunks. I would think can even use the titles/words or whatever for both the domain name and also the titles if wanted, unless need specific. Make the calling of the name of the file a random number variable something like $random_number.txt

 

I'm pretty sure can do something like mt_rand and floor of the file and get just a few lines, but I would think still counting the lines in a 1 gig + file still takes usage.

 

Well right now I have no time, have to fix my sisters busted furnace, but maybe within next few days I'll write up a complete system using multiple text files and have as a download for everyone. I been wanting to make a more advanced system with jumbling words for domain creations and then save the domains created into alphabetical lists and broken up into say 100,000 per file.

 

I have a system now that uses mysql, basically i insert a new word in, adds all 500 or w/e tld or sld's for that domain,checks alive or dead. Didn't seem very efficient calling to mysql each time so I stopped that project for now. It was something I was deciding how I really want it done, save just alive..or all, which even dead sites have value for buying new domains but to save every possible combination seem ludicrous. I can't even do the math on that, url's can be 255 positions and also is 500+tld and sld's, mix that with a combination of every single letter and number and that's an insane amount.

 

The reason why gonna make something a bit more dynamic so is no need to save every possible combination, but with a cost of server usage versus storage space.

 

So I'll post when I do this.

Link to comment
Share on other sites

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

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

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

×   Your previous content has been restored.   Clear editor

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

×
×
  • Create New...

Important Information

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