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 4625350
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:15:35+00:00 2026-05-22T03:15:35+00:00

I have code generating a random font and applying a new random font to

  • 0

I have code generating a random font and applying a new random font to each line of text and would like to add a

$line = str_replace ("a", "@", $line);

But I would like the chance of this being applied to each line to be 10% rather than applied to the string as a whole. How can i do it? Here’s my existing code:

$fonts = array("Helvetica", "Arial", "Courier", "Georgia", "Serif", "Comic Sans", "Tahoma", "Geneva", "Times New Roman");
shuffle($fonts);

$output = "";

$lines = array_slice(file("users.txt"), -20, 20);

$i = 0;
foreach ( $lines as $line ) {
  if($i == count($fonts)) {
    shuffle($fonts);
    $i = 0;
  }
  $output .= '<div style="font-size: ' . rand(15, 23) . 'px; font-family:' . $fonts[$i] . '; margin-left: ' . rand(0, 60) . '%; opacity: 0.8;">' . $line . "</div>\n";
  $i++;
    }

echo $output;

I’m just starting to get familiar with php, I feel as though I’ve got a whole new web to play with! 😀

  • 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-05-22T03:15:36+00:00Added an answer on May 22, 2026 at 3:15 am

    If you’d like to have 10% chance of having your ‘a’ changed with ‘@’ then try inserting this code:

    if(rand(0, 9) == 1)
    {
        $line = str_replace ("a", "@", $line);
    }
    

    It generates an Integer from 0 – 9 and if it equals 1 (10% chance, then it applies your formatting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following snippet of code that's generating the Use new keyword if
I have following code that is generating random no. between 1 to 10. This
I have a standalone Java application below that is: Generating a random line Applied
I would like to know how I could generate code from a text file
I have ASP.Net code generating my button's HTML for me using divs to get
For example, I have a piece of code that's generating a SQL*Loader control file
i am generating *.reg file using code which will have some important data. and
I have a bit of code which is annoying me because it is generating
I have code that references a web service, and I'd like the address of
I have two great tables that I would like to use as foundation for

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.