Jump to content

How to randomly pass keywords from text file in URL


seblondres

Recommended Posts

Hi,

 

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

<?php
$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
Link to comment
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');

 

Thanks,

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...