/    Sign up×
Community /Pin to ProfileBookmark

need help with a project

hey guys hows it going… new to the forums here… i’m currently working on a lil code for “Random Quotes” ok well i have it working very nice but still not what’s desired, i’ll explain…

its here as a demo: [url]http://abkclan.com/test/rotate.html[/url]

currently its getting the random quote list from rotate.js in a list like this…

[CODE]
rotateQuotes.quotes = [
“quote 1 here”,
“quote 2 here”,
“quote 3 here”,
“quote 4 here”,
“quote 5 here”,
“quote 6 here”,
];
[/CODE]

well i could and have entered the data in like that… however i want to get the quote strings from a file ‘http://anybodykillas.com/Quotes.txt

the data would look like this in the file:

[CODE]
quote 1 here
quote 2 here
quote 3 here
quote 4 here
quote 5 here
quote 6 here
[/CODE]

what i need is to gather this data from Quotes.txt and put it in the format used in rotate.js

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@_ABK_NecroauthorMar 03.2012 — my guess is i'll have to get all the strings by doing a split at each new line (n) then they will be array'd so they are separated, then some how do a string replace. i suppose the first string: quotes[0] to be like this:

"rotateQuotes.quotes = [ " quotes[0] ","

the middle would be like this:

"" quotes[1] ","

and the last like this:

"" quotes[1] "]&#59;"


idk why im here ? RAGE! can't figure it out...

want it from the Quotes.txt because our bot saves quotes from our mIRC chat rooms to that file.


couple of people say i just have to do my random quotes differently where it splits the string and randoms the array id number.

others say i need jquery for what i wanna do but i wouldnt see y considering its just javascript anyways
Copy linkTweet thisAlerts:
@hyperionXSMar 03.2012 — use PHP to get quotes from file.
[code=php]
$quotes = file('Quotes.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
[/code]

and here is the javascript
[CODE]
rotateQuotes.quotes = ["<?php echo implode('","', $quotes)?>"];
[/CODE]
Copy linkTweet thisAlerts:
@Angry_Black_ManMar 03.2012 — PHP isn't necessary to do what you're asking. you can keep everything native an just use AJAX to request the contents of the text file. here's an example of doing just that:

http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first

in your case, you wouldn't just be placing the entire contexts of the text file into your page using "innerHTML". you'd have to be a bit (a lot) more precise. so, what you'd do is take the responseText and place each quote within the responseText into an instance in some array. that could be done using the "split" function against the responseText string, splitting at any instance of n

so if your text file said:

quote 1 here
quote 2 here
quote 3 here
quote 4 here
quote 5 here
quote 6 here


and you split it based on "n", you'd get an array that looked like:

[0] = "quote 1 here"
[1] = "quote 2 here"
[2] = "quote 3 here"
...


then, using more javascript, you randomize the quote and insert it into the DOM. EASY!!!
Copy linkTweet thisAlerts:
@_ABK_NecroauthorMar 04.2012 — thx the PHP method will work great i do believe...

at first was tring to avoid PHP scripts because there not allowed on the site being used... however i just made this on my own host and added it to the theme in the location desired with an iframe, my host allows php so i dont have to avoid using it anymore... lol didnt think about it, was stuck on making it work with js, and everything i tried failed ?
Copy linkTweet thisAlerts:
@_ABK_NecroauthorMar 04.2012 — ok yea the PHP method failed for some reason not sure why.... maybe i did it wrong idk...

well think he desided just to update the file with the list, with the bot instead of making a Quotes.txt file... think ima try the AJAX method later. idk nothing in AJAX lol only what it is and what its made to do... do believe i need to learn ?
×

Success!

Help @_ABK_Necro spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...