[PHP] Sorting and cleaning strings
Ok personally i dont know enough php to write somethin like this. It actually seems like it would be simple. No im not sayin please write this for me, Just askin if someone might already have this or maybe tell me a way to start it.
What I want it to do
It has a box probably a iFrame.
I paste in a list of lines that look somethin like this:
[code]
2214#
Re: [Request/Help]PHP Script.
If the data doesn't come out a database:
1. Place all items in an array.
2. Sort them using asort
If the data does come from a database:
1. Modify your select query to include "ORDER BY field_name ASC"
Stripping numbers and #:
use preg_replace() with a query matching any amount of numbers followed by a # and replace that with a '_'.
Easy as pie really :icon6:
Re: [PHP] Sorting and cleaning strings
Lol thanks if i only knew what any of that meant. And thanks for editing the title because i had no clue what to put the title as.
EDIT: is there anything i can use already made that would atleast sort them out? i wouldn mind renaming 14,xxx things if they was asorted in order
Re: [PHP] Sorting and cleaning strings
Felt in a good mood :wink:
If you don't know what it means, LEARN! The PHP manual is the best manual I've ever read (and I've read a LOT, trust me :wink:), you'll figure it out. And if you can't, you shouldn't be medling with this stuff anyway.
As for your regular expression, since I know these can be a bitch I'll help you out here:
[php]
$data = "2214#
Re: [PHP] Sorting and cleaning strings
ah you see i love learnin but as of tomorrow i wont be able to do much of it. and i will read them when i do get the time, i get the stuff specially when you put it into lamish. just took me less time to understand. *thinks to self* "i knew i shoulda chose php over c++" -.-. thanks alot you've always helped me on here without goin off over a stupid question ^^. as for my other question are there any websites i could imput maybe a list like this:
[code]
2205#
Re: [PHP] Sorting and cleaning strings
READ MY POST!
I've already told you twice: put them in an array and use asort()!
Re: [PHP] Sorting and cleaning strings
ah! i just read over it, thanks ^^ only thing is gona be a pain is addin in all 14k items.. owell. guess ill have to figure out a way to make it where i can just paste the data into it
Re: [PHP] Sorting and cleaning strings
Well, you could also store the 14k items into a database and read them from there - that wouldn't be that much of a pain I guess, and then sort them using SQL's ORDER BY.
Otherwise a simple while loop will also work (while($array[$i++] = $next_item)), it'll just take a while to run.
Re: [PHP] Sorting and cleaning strings
thanks for the help fragfrog, i talked to my step dad he said he would write me a prog in unix or perl ^^
Re: [PHP] Sorting and cleaning strings
.... the prog already exists. Its called asort.
In fact, if you have all those entries in a single file, you can read, sort and write the sorted list with just 3 lines of code:
PHP Code:
$string_array = file('datafile.txt'); // read all the lines in datafile.txt
$sorted_array = asort($string_array); // sort them in alphabetical order
file_put_contents('sorted_datafile.txt', $sorted_array); // We're being fancy and storing them too
Really, if you're not even going to -try-... :eh: