Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,048 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,564 people online right now. Registration is fast and FREE... Join Now!




Help With String

 
Reply to this topicStart new topic

Help With String

arniie
12 Nov, 2002 - 07:46 AM
Post #1

D.I.C Addict
****

Joined: 8 Oct, 2002
Posts: 999

Ive got a txt file which is a scoreboard

if i echo it, i get

32.5¬33.2¬36.2¬36.8¬39¬0 cmeeg¬TMM¬Dean¬cmeeg¬ArnIIe¬End 40¬40¬42¬44¬46¬0 TMM¬ArnIIe¬cmeeg¬ArnIIe¬ArnIIe¬End


i want to get the first time (32.5) - I know i can use substr - but the first value might be 32 (not with .5) therefore i need to get the number before the first ¬

how do i achieve this??
User is offlineProfile CardPM
+Quote Post

Koenie
RE: Help With String
12 Nov, 2002 - 08:11 AM
Post #2

What?!
*****

Joined: 8 Jul, 2002
Posts: 1,313

Isn't it possible to make the 32: 32.0? Then you can just use substr()

Koenie
User is offlineProfile CardPM
+Quote Post

arniie
RE: Help With String
12 Nov, 2002 - 08:15 AM
Post #3

D.I.C Addict
****

Joined: 8 Oct, 2002
Posts: 999

no - i can't change it
User is offlineProfile CardPM
+Quote Post

klewlis
RE: Help With String
12 Nov, 2002 - 09:10 AM
Post #4

cur tu me vexas?
*****

Joined: 9 Nov, 2001
Posts: 1,723

retrieve the whole string, split it into an array, and take the first element of the array.

CODE

$yourarray = explode("-,", $yourstring);
$score = $yourarray[0];

User is offlineProfile CardPM
+Quote Post

arniie
RE: Help With String
12 Nov, 2002 - 09:13 AM
Post #5

D.I.C Addict
****

Joined: 8 Oct, 2002
Posts: 999

i tried that but it won't explode the string with the ¬ delimeter ?

explode ("¬", $mystring);
User is offlineProfile CardPM
+Quote Post

cooguy
RE: Help With String
12 Nov, 2002 - 11:48 AM
Post #6

New D.I.C Head
*

Joined: 22 Oct, 2002
Posts: 3

Split every character and put it in one big array. Then find what location the "¬" is, then just take all the all the array elements from the first (0) to the array element one before the "¬"
User is offlineProfile CardPM
+Quote Post

klewlis
RE: Help With String
12 Nov, 2002 - 05:11 PM
Post #7

cur tu me vexas?
*****

Joined: 9 Nov, 2001
Posts: 1,723

why won't it explode with that character? i've passed weird characters before and they worked...
User is offlineProfile CardPM
+Quote Post

arniie
RE: Help With String
13 Nov, 2002 - 01:20 AM
Post #8

D.I.C Addict
****

Joined: 8 Oct, 2002
Posts: 999

i think ive sorted it - haven't tried yet, this should work tho... hopefully!!

<?
$fd = fopen( "flash/highscores.txt", "r" );
while (!feof ($fd)) {
$buffer = explode( "¬", fgets($fd,4096) );
print_r( $buffer[0] ); ?> <br> <?
}
echo $txt;
?>
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 05:32PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month