Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8034083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:54:00+00:00 2026-06-05T01:54:00+00:00

trying to set up a simple embed box to echo url and randomize source

  • 0

trying to set up a simple embed box to echo url and randomize source anchor text. I achieved both with this:

<textarea class="cf" onclick="this.focus();this.select()" readonly="readonly">
<iframe src="<?php
$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo $url;
?>" width="550px" height="400px" frameborder="0" scrolling="auto" allowtransparency="true"><a href="http://example.com/"><?php 
$raAnchor = array(1 => 'example.com', 
           2 => 'http://example.com/', 
           3 => 'www.example.com', 
           4 => 'Click here');  
$raNumber = count($raAnchor); 
echo $raAnchor[rand(1, $raNumber)]; 
?></a></iframe>
</textarea>

The problem: how do I weight random results from the array to favor a particular echo? For example, would like example.com to echo out 50% of the time.
I guess I could just put more example.com in the array like this:

1 => 'example.com', 
2 => 'example.com', 
3 => 'example.com', 
4 => 'example.com', 
5 => 'http://example.com/', 
6 => 'www.example.com', 
7 => 'Click here');  

Seems there has to be a more elegant solution. I’m new to programming, and php I understand the least so if you could point me in the right direction I can take it from there.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:54:01+00:00Added an answer on June 5, 2026 at 1:54 am

    You can do this:

    <?php
        if(rand(1,2) == 1)
        {
            //Example goes here
        }
        else
        {
            //Everything else
        }
    ?>
    

    You can do the same with intervals. For example:

    <?php
        $r = rand(1,10); 
        if($r >=1 && $r < 4)
        {
            /* 30% */
        }
        else if($r >=4 && $r < 9)
        {
            /* 60% */
        }
        else
        {
            /* 10% */
        }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set together a simple TextBox with some watermark text in the
I'm trying to set up a relatively simple AJAX pagination with jQuery like this:
This seems simple, I am trying to set a bitmap image but from the
I'm trying to set up a simple association in NHibernate (this is the first
I'm trying to set a callback function in Jack. This is usually quite simple,
This should be a simple syntax thing: I'm trying to set a variable in
I'm trying to set up a simple server side RSA encryption of a small
I'm trying to set up a simple SQLite database in Android, handling the schema
I'm trying to set up the simple syndication example from the Django docs, in
I am trying to set up a simple css transition where there is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.