Random Quotes in Signature -- Changing text

Need some coding help with a MOD or tweak you are working on? - Ask here.
Forum rules
Ask for support specifically regarding coding help with phpBB3.
Not for generic usability questions or support.

Re: Random Quotes in Signature -- Changing text

Postby posey » 14 Jan 2010, 05:34

Thanks a lot, that worked. However, you forgot one closing bracket but fortunately I could figure that one out myself ^^.
I thougth I already tried changing the 10 to 2, but I guess not.

Correct code would be:
Code: Select all
    $split_array = explode("\n", $quotes);
    $count = (count($split_array);
    $count = ($count < 10) ? $count : 10;
    $rand_keys = array_rand($split_array, $count);
posey    
Cadet I
Cadet I
 
Posts: 19
Joined: 09 Dec 2009, 16:47
Location: The Netherlands
Favorite Team: NAC Breda
Gender: Male
phpBB Knowledge: 7




phpBB Academy at StarTrekGuide
Support STG
Using PayPal Donate

Re: Random Quotes in Signature -- Changing text

Postby Sullivan » 27 Jan 2010, 04:08

That's great, I've been wondering how to do this aswell. Much appreciated :)
Sullivan
Crewman
Crewman
 
Posts: 5
Joined: 25 Jan 2010, 16:56
Gender: Female
phpBB Knowledge: 6

Re: Random Quotes in Signature -- Changing text

Postby reality » 16 Jun 2010, 09:21

here is what I have

Code: Select all
<?php
$quotes = 'Text1
Text2';
$split_array = explode("\n", $quotes);
$count = (count($split_array);
$count = ($count < 10) ? $count : 10;
$rand_keys = array_rand($split_array, $count);

header("content-type: application/x-javascript");
echo "<!--\n
document.write('{$split_array[$rand_keys]}');\n
//-->";
?>


and nothing happens - no text at all. It showed me last of two lines when I had

Code: Select all
$rand_keys = array_rand($split_array, 1);


but then I realized that right number would be 2 and changed it, everything disappeared. I also tried universal solution as I mentioned before, but it didn't work.

I wonder what I might be doing wrong...
reality
Crewman
Crewman
 
Posts: 2
Joined: 16 Jun 2010, 04:59
Gender: Male
phpBB Knowledge: 4

Re: Random Quotes in Signature -- Changing text

Postby RocknRoll » 09 Sep 2010, 00:58

Okay, I can't seem to get this to work.

This is exactly what I have, and I get nothing. :cray:
EDIT: ( Actually it adds the "space" for the line, but nothing else. )

1_random_sig_quote.php placed in my root ( where my config.php is )
Code: Select all
<?php

$quotes = 'Random Text 01
Random Text 02
Random Text 03
Random Text 04
Random Text 05
Random Text 06';

$split_array = explode("\n", $quotes);
$count = (count($split_array);
$count = ($count < 10) ? $count : 10;
$rand_keys = array_rand($split_array, $count);

header("Content-type: application/x-javascript");
echo "<!--\n";
    //echo 'document.write("' . $split_array[rand_keys] . '");' . "\n";
    echo 'var Quote = new Array()' . "\n";
    foreach ($rand_keys as $i => $value)
    {
        echo 'Quote[' . $i . '] = \'' . $split_array[$rand_keys[$i]] . '\';' . "\n";
    }
    echo 'var Q = Quote.length;
    var whichQuote = Math.round(Math.random() * (Q - 1));
    function showQuote()
    {
        document.write(Quote[whichQuote]);
    }
    showQuote();' . "\n";
echo '-->';

?>


BBCode usage
Code: Select all
[random]{NUMBER}[/random]

HTML replacement
Code: Select all
<script type="text/javascript" src="./path/to/scripts/{NUMBER}_random_sig_quote.php"></script>

In my signature
Code: Select all
[random]1[/random]
Grey Guard
User avatar
RocknRoll    
Cadet IV
Cadet IV
 
Posts: 49
Joined: 23 Mar 2010, 11:06
Location: Syracuse, NY
Favorite Team: Minnesota Vikings
Gender: Male
phpBB Knowledge: 4

Re: Random Quotes in Signature -- Changing text

Postby wadie » 09 Sep 2010, 14:41

Thanks a lot !

I think it suits my sig here as well. :P
PM me for private support or installing MODs/styles.
User avatar
wadie    
Lieutenant
Lieutenant
 
Posts: 329
Joined: 11 Mar 2010, 10:14
Gender: Male
phpBB Knowledge: 5

Re: Random Quotes in Signature -- Changing text

Postby RocknRoll » 10 Sep 2010, 10:29

This code is working

Code: Select all
<?php
$quotes = 'Random Text 01
Random Text 02
Random Text 03
Random Text 04
Random Text 05
Random Text 06';
$split_array = explode("\n", $quotes);
$rand_keys = array_rand($split_array, 1);

header("content-type: application/x-javascript");
echo "<!--\n
document.write('{$split_array[$rand_keys]}');\n
//-->";

?>
Grey Guard
User avatar
RocknRoll    
Cadet IV
Cadet IV
 
Posts: 49
Joined: 23 Mar 2010, 11:06
Location: Syracuse, NY
Favorite Team: Minnesota Vikings
Gender: Male
phpBB Knowledge: 4

Re: Random Quotes in Signature -- Changing text

Postby petesat » 11 Feb 2011, 22:26

I just used this one, and obviously, you do not have to show the BBCode to everyone on forum if you do not wish..

Code: Select all
Rotating Text BBcode

Author: Evan Holloway
Description: Prints a random text string (like a quote). This is often used in signatures. The number of strings goes in the tag option as an integer. The strings are seperated by underscore "_" in between the tags.


BBCode:

Code: Select all
    [rtxt={NUMBER}]{SIMPLETEXT}[/rtxt]


HTML:

    <script type="text/javascript">
    var qttxta = "{SIMPLETEXT}";
    var qtxtsel = qttxta.split("_");
    var qtnums = Math.floor(Math.random()*{NUMBER});
    document.write(qtxtsel[qtnums]);
    </script>


Helpline:
    Random string rotator: [rtxt=number_of_strings]strings_seperated_by_bars[/rtxt]


Example:
    [rtxt=8]Quote 1_Quote 2_Quote 3_Quote 4_Quote 5_Quote 6_Quote 7_Quote 8[/rtxt]


This is a lot easier for some of the newer to PHPBB, just for info. ;)

This was found here..

Code: Select all
http://www.phpbb3bbcodes.com/viewtopic.php?f=2&t=77
User avatar
petesat
Cadet I
Cadet I
 
Posts: 16
Joined: 16 Apr 2008, 08:36
Gender: Male

Re: Random Quotes in Signature -- Changing text

Postby Honor » 09 Apr 2011, 11:54

Is there a way to make this work for images? Am willing to host images for people on my website (there aren't a lot and I doubt many would use it, as few put time into multiple sigs, but I want it for myself :D)
BluePlanet RP
my own creation.

Host: Host Monster
Version: 3.0.9
Honor    
STG Moderator
STG Moderator
 
Posts: 328
Joined: 23 Dec 2010, 10:53
Gender: Female
phpBB Knowledge: 2

Re: Random Quotes in Signature -- Changing text

Postby Honor » 09 Apr 2011, 12:46

NEVERMIND! I figured it out :D I now have both, random quotes, and random sigs on my forum :)


I do have a question though. Is it possible to adapt this to show certain sigs only in certain forums (I'm guessing with a string of "if" statements)? I know how to do it in HTML, sort of, but I don't know how to adapt it for things like the Arcade and the memberlist view document, and I am not entirely sure on the syntax of the forum view. I will put the work into it if someone could give me an example to get me started.
BluePlanet RP
my own creation.

Host: Host Monster
Version: 3.0.9
Honor    
STG Moderator
STG Moderator
 
Posts: 328
Joined: 23 Dec 2010, 10:53
Gender: Female
phpBB Knowledge: 2

Re: Random Quotes in Signature -- Changing text

Postby RocknRoll » 28 Sep 2011, 09:40

** problem solved **
Grey Guard
User avatar
RocknRoll    
Cadet IV
Cadet IV
 
Posts: 49
Joined: 23 Mar 2010, 11:06
Location: Syracuse, NY
Favorite Team: Minnesota Vikings
Gender: Male
phpBB Knowledge: 4

Previous

Return to phpBB3 Coding Assistance

Who is online

Users browsing this forum: Googlebot and 11 guests