473,385 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Generate Random URL

1
hello everyone im not that much familiar with php and i want to create a function that output random url from the ones provided in the array so whenever i click generate one url will apear in the text field pllzzz i need help :(

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. if (isset($_POST['generate'])){
  4. $urls = array('http://domain.com/a/a.jsp','http://domain.com/a/b/a.jsp','http://domain.com/a/b/b.jsp','http://domain.com/a/b/c.jsp','http://domain.com/a/c/1.jsp','http://domain.com/a/d/2.jsp','
  5. http://domain.com/a/d/a/2.jsp' );
  6. $array = array(); 
  7. print_r($array); 
  8.  
  9. }
  10. ?>
  11. <form action = "new.php" method= "POST">
  12. <input type= "submit" name = "generate" value="generate"/> <input type = text value = ""/>
  13. </form>
  14.  
May 27 '12 #1
1 2245
try this:

Expand|Select|Wrap|Line Numbers
  1. echo $urls[rand(0,sizeof($urls)-1)];
May 28 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Yudan YI \(OSU\) | last post by:
I want to generate random data from a normal distribution, while I checked the functions, and I found rand(), which returns a pseudorandom integer between zero and RAND_MAX. I am not sure how to...
4
by: Marc Dansereau | last post by:
Hi all, I wonder what is the most efficient way to generate random point on a line defined by 2 double points (x0,y0) and (x1,y1). Here is the pseudocode of my method : for each point {...
7
by: MattB | last post by:
I have the following code to generate random passwords for new users of an application. Const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstyvwxyz1234567890" Dim r As Int16, i As...
6
by: comp.lang.php | last post by:
/** * Generate the random security image * * @access public * @param $willUseFilePath (default false) boolean to determine if you will be using a file path * @param mixed $filePath (optional)...
0
sashi
by: sashi | last post by:
Generate Random Password In the course of programming you may have cause to generate a password. The following function will generate a password of randomly selected characters up to a maximum of...
3
by: jjmontreal | last post by:
I would like to create a form where by clicking some where in the form it will generate a alphanumeric sequence. I want to generate random PIN numbers preceeded with specific letters. An example...
9
by: Chelong | last post by:
Hi All I am using the srand function generate random numbers.Here is the problem. for example: #include<iostream> #include <time.h> int main() {
4
by: pitchke | last post by:
how do i generate random no's...also i want to convert that no. to the corresponding string...using PHP!!!!! thanks in advance.. Tarun
24
by: pereges | last post by:
I need to generate two uniform random numbers between 0 and 1 in C ? How to do it ? I looked into rand function where you need to #define RAND_MAX as 1 but will this rand function give me ...
1
Srijith B
by: Srijith B | last post by:
HI all I am trying to write a perl script to generate random names ed. ( Qrhfh, Jdfhdh, Dfkjns) etc. So the script should ask me the number of random names and when I give say 4, It should give...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.