Jump to content

How to randomly pass keywords from text file in URL

Recommended Posts



I have this script below which select random keywords from a file:

$search = explode("\n", file_get_contents('keywords.txt'));
$search[ array_rand($search) ]; 

Now I want to randomly pass those keywords in an URL so I can $_Get them e.g. http://example.com/index.php?keyword={A random keyword from my text file}


If someone could point me to the right direction.


Many Thanks,

Edited by seb_london

Share this post

Link to post
Share on other sites

Ok I found a solution to my post:

$keywords = explode("\n", file_get_contents('keywords.txt'));
$search = $keywords[ array_rand($keywords) ];

Instead I passing the random keywords as a query keyword='.$search.' in my API url: e.g.


$productsResult = simplexml_load_file('http://site.com?publisherId=xxx&placementId=&categoryId=&keyword='.$search.'&apiKey=xxxx');




Share this post

Link to post
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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