![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| PHP PHP for some can be one of the hardest website programming codes, so do you need help on your PHP script, if it is php4, php5 or lower this is the place for you for any PHP help. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| Hi, I was trying to do the following. It's my first php "project", so it's quiet logic that i have some problems. Perhaps the php community might help. It's about this : I have a txt file with the following data : 1. Stijn Piot 58.12; 2. Kim Van Rooy 1.25; 3. Johnny Marcovich 2.37; 4. John Terlaeken (Bel) 1 ronde/tour; 5. Michael Bertrand 2.12; It's a ranking of a race. Now what i want to reach is, that these names, come into an array, eventually in an sql database. But the last thing, is not this big problem, if I succeed in getting it into an array. So the result might look something like this Stijn Piot Kim Van Rooy .... It would be even cooler, if in front of these names was 1 | Stijn Piot | 58.12 2 | Kim Van Rooy | 1.28 3 | .... | 2.54 .... 10| John Terlaeken | 1 ronde/tour/round behind Now the last thing, I didn't tried, because it seems to complicated for my first "project". The first however must be possible, and it can't be that difficult. This is what I had, but it didn't worked. Can somebody help me to reach the exact result. Thankx in advance <? php $textfile = "1. Stijn Piot 58.12; 2. Kim Van Rooy 1.25; 3. Johnny Marcovich 2.37; 4. John Terlaeken (Bel) 1 ronde/tour; 5. Michael Bertrand 2.12;" // this is a part of the textfile $position=split("\;", $textfile); //splitting in an array with the semicolon, the result is an array with rows like this 1. stijn piot 58.12 $max = count($position); // counting the size of the array $i =0; For ($i=0; $i<$max; $i++) { $time = split ("^[0-9]+\.[[:space stijn piot 58.12 is splitted according "number space", the result is stijn piot 58.12 $name = split ("[0-9]+\.[0-9]+", $time[1]); echo $name[0]; // the previous result stijn piot 58.12 is splitted according "number.number", the final result should be stijn piot } // because it is a for loop, eventually i should have //stijn piot //kim van rooy //.... but the farest i can get is just stijn piot and further nothing. ?> It's not easy at all, i hope the community can do something for me. I'm sure that this script can help quiet a lot of people. Ciao Stijn | |||
| | #2 | ||
| "nieuws" <stijnthe1st@yahoo.com> wrote in news:Lao0b.74958$F92.8325@afrodite.telenet-ops.be: > I have a txt file with the following data : > > 1. Stijn Piot 58.12; 2. Kim Van Rooy 1.25; 3. Johnny Marcovich 2.37; > 4. John Terlaeken (Bel) 1 ronde/tour; 5. Michael Bertrand 2.12; > $position=split("\;", $textfile); //splitting in an array with the > semicolon, the result is an array with rows like this 1. stijn piot > 58.12 > $max = count($position); // counting the size of the array Why are you escaping the semicolon? It does not need escaping, you should've gotten an error about it (try setting your ERROR_REPORTING to E_ALL while testing). > $i =0; > For ($i=0; $i<$max; $i++) { > $time = split ("^[0-9]+\.[[:space > 1. > stijn piot 58.12 is splitted according "number space", the result is > stijn piot 58.12 > $name = split ("[0-9]+\.[0-9]+", $time[1]); > echo $name[0]; // the previous result stijn piot 58.12 is splitted > according "number.number", the final result should be stijn piot > } I don't understand what you're doing here. Why split it several times, with those strange patterns? Just split it once (looks to me like you're only interested in the name, and not the time): $name = split ("[0-9]", $position[$i]); I recommend you use the PCRE functions, they're faster and have a very good (IMHO) RegEx engine. http://www.php.net/manual/en/ref.pcre.php KAH | |||
| Featured Websites | ||||
|
![]() |
| Tags: command, split |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| split screen | Paul | Console Subjects | 3 | 06-26-2007 2:03 PM |
| Split screen | Rob | Console Subjects | 3 | 06-26-2007 1:41 PM |
| Split a all-databases dump | Fabian Schulz | Database | 0 | 05-31-2007 8:39 PM |
| RE: split with regex | Armand B | PHP | 0 | 05-20-2007 6:33 PM |
| split with regex | Patrick | PHP | 4 | 05-20-2007 6:33 PM |
| Featured Websites | ||||
|