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 Mr_Bond » 17 Feb 2009, 19:20

Finsta, make sure no spaces or characters are before the <?php, it looks as though there is a space there ;)
User avatar
Mr_Bond    
Lieutenant
Lieutenant
 
Posts: 246
Joined: 14 Feb 2008, 14:45
Location: localhost
Favorite Team: Chicago Bears
Gender: Male
phpBB Knowledge: 7


Re: Random Quotes in Signature -- Changing text

Postby Tikva » 18 Feb 2009, 05:24

Code: Select all
<?php

$quotes =
"It takes a big man to cry, but it takes a bigger man to laugh at that man.
After an incident in Croydon involving a police van and a concrete mixer, police are looking for eighteen hardened criminals.
Psychology: Mind over matter. Mind under matter? It doesn\'t matter. Never mind.
Right now I\'m having amnesia and deja vu at the same time - I think I\'ve forgotten this before...
I love giving opinions, I\'ve got thousands.
Someday, you\'ll look back on this topic, laugh nervously and change the subject.
I don\'t suffer from insanity, I enjoy every minute of it.
For my birthday I got a humidifier and a de-humidifier... I put them in the same room and let them fight it out.
You know, 50% of doctors graduated in the BOTTOM HALF of their class.
Nobody can get the truth out of me because even I don\'t know what it is. I keep myself in a constant state of utter confusion.
Any connection between your reality and mine is purely coincidental.";
$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
//-->";
?>


The above is the entire contents of my 7_signature.php file, and with this, I also have the problem where it is only the last quote that ever shows up, and the rest of the time nothing does. Any ideas?
Tikva    
Cadet I
Cadet I
 
Posts: 15
Joined: 19 Dec 2008, 23:58
Location: Dunedin, New Zealand
Gender: Female
phpBB Knowledge: 3

Re: Random Quotes in Signature -- Changing text

Postby terryzx » 18 Feb 2009, 11:38

you could duplicate the last quote to add it above that last one :grin:
terryzx    
Supporter
Supporter
 
Posts: 164
Joined: 09 Aug 2008, 21:26
Gender: Male
phpBB Knowledge: 4

Re: Random Quotes in Signature -- Changing text

Postby Tikva » 18 Feb 2009, 15:34

Huh? Me confused.......
Tikva    
Cadet I
Cadet I
 
Posts: 15
Joined: 19 Dec 2008, 23:58
Location: Dunedin, New Zealand
Gender: Female
phpBB Knowledge: 3

Re: Random Quotes in Signature -- Changing text

Postby terryzx » 18 Feb 2009, 15:52

Tikva wrote:Huh? Me confused.......



For instance:

#1
#2
#3
#4
#5
#5 (again)

This is not a fix...but it might get that lost line to work also
terryzx    
Supporter
Supporter
 
Posts: 164
Joined: 09 Aug 2008, 21:26
Gender: Male
phpBB Knowledge: 4

Re: Random Quotes in Signature -- Changing text

Postby Tikva » 22 Feb 2009, 03:34

Ohhh, I get you now. Unfortunately, the last line is the ONLY line that works.
Tikva    
Cadet I
Cadet I
 
Posts: 15
Joined: 19 Dec 2008, 23:58
Location: Dunedin, New Zealand
Gender: Female
phpBB Knowledge: 3

Re: Random Quotes in Signature -- Changing text

Postby terryzx » 22 Feb 2009, 05:31

Oh I see....

Try this and replace it with your own quotes

I used this and it worked fine:

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
//-->";

?>


Be sure the single quote is ONLY in front on the start and then at the end
terryzx    
Supporter
Supporter
 
Posts: 164
Joined: 09 Aug 2008, 21:26
Gender: Male
phpBB Knowledge: 4

Re: Random Quotes in Signature -- Changing text

Postby Highway of Life » 22 Feb 2009, 11:34

Didn?t realise people were still using my old code.

The new code has been updated with the post: viewtopic.php?p=37780#p37780
You have to ensure your file is saved with Unix line endings (LF), not Windows line endings (CRLF).
Watch out! I might do a code wheelie!

User avatar
Highway of Life    
STG Jedi Master
STG Jedi Master
 
Posts: 10458
Joined: 08 May 2006, 05:23
Location: Beware of Programmers carrying screwdrivers
Gender: Male
phpBB Knowledge: 10

Re: Random Quotes in Signature -- Changing text

Postby Tikva » 22 Feb 2009, 18:08

Regarding the Line Endings, does the same rule apply regardless of what your website server is running? My website host is windows-based, not Unix, and I am still unable to get this code to work. I have used Notepad Plus to create/edit the php file, ensured that it is in Unix format, as well as UTF-8 without BOM, uploaded it, but still no go. I've tried it in ANSI format, instead of UTF-8 without BOM, converted it to Windows format, and a few other things, but it just isn't working for me.

Also, is it necessary with the updated code to but the '\' in front of all apostrophes?
Tikva    
Cadet I
Cadet I
 
Posts: 15
Joined: 19 Dec 2008, 23:58
Location: Dunedin, New Zealand
Gender: Female
phpBB Knowledge: 3

Re: Random Quotes in Signature -- Changing text

Postby terryzx » 22 Feb 2009, 19:36

One thing that you may be having a problem with is if you somehow acquired invisible characters

These will kill any code and leave you wondering why?????

I find that most every time I copy something from a web page, I get them, so I have to make them visible and remove them

You can see them if you change the .php extension to .txt and then look at it in the browser when pulling it from your site

There are applications that will also show these too

When I copy from the XML file, I never have this problem
terryzx    
Supporter
Supporter
 
Posts: 164
Joined: 09 Aug 2008, 21:26
Gender: Male
phpBB Knowledge: 4

PreviousNext

Return to phpBB3 Coding Assistance

Who is online

Users browsing this forum: contemporary2, Ezooms Bot and 10 guests