[php]Hoe text in array elementen verdelen?

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • commeric
  • Registratie: November 2002
  • Laatst online: 14-08 22:32
Hoe splits ik deze regel op in 4 array elementen
FantasyGirl (X:9,Y:3) Volcanic Inferno 1,360 310,396
[____________________] [______________] [____] [______]

Volcanic inferno kan ook Oceanic zijn, dus maar 1 woord.
Maar hoe laat ik php dat dan herkennen?
HEt moet uit de pagina hieronder komen.

Wie weet hoe dit precies heet, en waar ik meer info over dit onderwerp kan vinden. Want deze functies om strings en teksten te veranderen, op te zoeken, en te splitsen. snap ik niet helemaal


---------------------------------------

ADVERTISEMENT (More Info)

Read Messages No News January 4, 4:36 PM Networth: 354,321
Money: 180,945 Power: 143,618 Population: 16,708 Land: 1,231

« Galaxy: Sector:

»


The Sector Of: under 500k nw = 2x retals [Luminatx] (2:38)

The Yellow kingdom is the sector leader.
Any Blue kingdom is still a newbie.
Any Green kingdom is in vacation mode.
Any Red kingdom has been disabled by the admins.
Your kingdom is shown in Orange
Any kingdom with an @ symbol after its name is currently online

Kingdom Name (Sector Coords) Planet Type Land Networth Tactical
FantasyGirl (X:9,Y:3) Volcanic Inferno 1,360 310,396
ghomes49ers (X:3,Y:1) Forest and Wilderness 225 16,580
Stalides (X:10,Y:6) Multiple Terrain 250 23,060
Avaqui (X:6,Y:6) @ Oceanic 1,585 384,928
me (X:3,Y:10) Forest and Wilderness 250 17,997
IdAp (X:3,Y:6) Mountainous 445 61,005
REALM OF DOOM (X:3,Y:2) Desert Wasteland 10,991 3,482,840
Session9 (X:7,Y:7) Mountainous 2,189 494,434
Dragons Lair Unite (X:5,Y:1) Forest and Wilderness 63 6,043
Galum (X:7,Y:1) Oceanic 109 8,225
Purmerend (X:6,Y:10) @ Forest and Wilderness 2,237 699,227
Nevykes ART istas (X:8,Y:1) Mountainous 5,574 1,778,710
Conflict (X:1,Y:2) Mountainous 1,115 295,153
Tarosian Empire (X:1,Y:6) Multiple Terrain 3,151 753,822
Evil Dome (X:4,Y:5) Mystical Lands 253 16,078
Land of Xanth (X:3,Y:7) Mystical Lands 1,377 252,463
Nalkalaakso (X:2,Y:10) Terra Form 2,299 511,322
Draconis Centauri (X:10,Y:9) Forest and Wilderness 145 13,934
Cuba (X:9,Y:2) Volcanic Inferno 250 16,339
land of flecher (X:4,Y:3) Mountainous 152 13,286


Total Sector Networth: 9,155,842


Game Help
Money: 180,946 Power: 143,618 Population: 16,708 Networth: 786876

Acties:
  • 0 Henk 'm!

Verwijderd

PHP:
1
$var = explode(" ", $string);


$string: jouw data (FantasyGirl (X:9,Y:3) Volcanic Inferno 1,360 310,396)
$var: array waarin de data staat

Acties:
  • 0 Henk 'm!

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06 13:31

drm

f0pc0dert

CowMike:
PHP:
1
$var = explode(" ", $string);


$string: jouw data (FantasyGirl (X:9,Y:3) Volcanic Inferno 1,360 310,396)
$var: array waarin de data staat
"Dragons Lair Unite"

:o oops.

Ik denk dat je met regexen aan de gang moet. Beschrijf het patroon op zo'n manier dat de verschillende onderdelen in de "tabel" niet met elkaar in verwarring gebracht kunnen worden. pcre

(of zorg dat je 't in xml formaat opgestuurd krijgt, ofzo, dat maakt 't allemaal nog een heel stuk eenvoudiger) xml of domxml

[ Voor 35% gewijzigd door drm op 05-01-2003 10:42 ]

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


Acties:
  • 0 Henk 'm!

Verwijderd

Met een regex moet het lukken. De match

<nummer><haakje sluiten> <spatie><nummer>
Daaree trek je de twee hoofdgroepen uit elkaar, daarna is het simpeler.. Regexen zijn behoorlijk lastig, gewoon gaan spelen en zien wat ie doet

Acties:
  • 0 Henk 'm!

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06 13:31

drm

f0pc0dert

Is de tekst overigens niet heel toevallig in tabtekens onderverdeeld? In dat geval kun je nl. gewoon op "\t" exploden

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


Acties:
  • 0 Henk 'm!

  • commeric
  • Registratie: November 2002
  • Laatst online: 14-08 22:32
het is eigenlijk een tabel, ik weet niet of <td> ook als tab geld?

Acties:
  • 0 Henk 'm!

  • martinvw
  • Registratie: Februari 2002
  • Laatst online: 20-08 20:35
neej, maar dan kan je natuurlijk wel op die <td>'s splitsen :)

Acties:
  • 0 Henk 'm!

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06 13:31

drm

f0pc0dert

tja, is het nou text, of HTML wat je gaat filteren :? :?

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


Acties:
  • 0 Henk 'm!

  • commeric
  • Registratie: November 2002
  • Laatst online: 14-08 22:32
text, geen html.
Dus de informatie is zoals ik hier boven heb beschreven.

dit kreeg ik van iemand anders:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php 

$strings = array ( 
    "FantasyGirl (X:9,Y:3)  Volcanic Inferno 1,360 310,396", 
    "ghomes49ers (X:3,Y:1)  Forest and Wilderness 225 16,580", 
    "Stalides (X:10,Y:6)  Multiple Terrain 250 23,060", 
    "Avaqui (X:6,Y:6) @ Oceanic 1,585 384,928", 
    "me (X:3,Y:10)  Forest and Wilderness 250 17" ); 

foreach ($strings as $str) { 
    $res = preg_match("#([a-z0-9_]+)\s+\(([^\)]+)\)\s+@?([a-z\s]+)\s+([0-9]+(?:,[0-9]+)?)\s+([0-9]+(?:,[0-9]+)?)#i", $str, $matches); 
    echo "$matches[1] ($matches[2])\t\t$matches[3] $matches[4] $matches[5]\n"; 
} 
?> 

maar dan zijn de strings al gescheiden. Hoe haal ik die dingen dan uit de txT?

ik dacht zelf iets van
PHP:
1
2
3
<?
$strings = explode("\n", $txt);
?> 

waar $txt de hele text bevat, en $strings dan de gescheiden elementen zijn

[ Voor 23% gewijzigd door commeric op 05-01-2003 16:04 ]


Acties:
  • 0 Henk 'm!

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06 13:31

drm

f0pc0dert

probeer 't eens zou ik zeggen ;)

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


Acties:
  • 0 Henk 'm!

  • commeric
  • Registratie: November 2002
  • Laatst online: 14-08 22:32
:D:D mijn ged8te gang klopte voor het eerst :D, dank jullie wel :D

ik ben nu zover, maar ik heb er wel vaker last van dat ie offset errors geeft als een array niet bestaat. HOe kan ik dat controleren?

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
$txt="ADVERTISEMENT (More Info) 

Read Messages No News January 4, 4:36 PM Networth: 354,321 
Money: 180,945 Power: 143,618 Population: 16,708 Land: 1,231 

« Galaxy: Sector: 

»


The Sector Of: under 500k nw = 2x retals [Luminatx] (2:38) 

The Yellow kingdom is the sector leader. 
Any Blue kingdom is still a newbie. 
Any Green kingdom is in vacation mode. 
Any Red kingdom has been disabled by the admins. 
Your kingdom is shown in Orange 
Any kingdom with an @ symbol after its name is currently online 

Kingdom Name (Sector Coords) Planet Type Land Networth Tactical 
FantasyGirl (X:9,Y:3) Volcanic Inferno 1,360 310,396 
ghomes49ers (X:3,Y:1) Forest and Wilderness 225 16,580 
Stalides (X:10,Y:6) Multiple Terrain 250 23,060 
Avaqui (X:6,Y:6) @ Oceanic 1,585 384,928 
me (X:3,Y:10) Forest and Wilderness 250 17,997 
IdAp (X:3,Y:6) Mountainous 445 61,005 
REALM OF DOOM (X:3,Y:2) Desert Wasteland 10,991 3,482,840 
Session9 (X:7,Y:7) Mountainous 2,189 494,434 
Dragons Lair Unite (X:5,Y:1) Forest and Wilderness 63 6,043 
Galum (X:7,Y:1) Oceanic 109 8,225 
Purmerend (X:6,Y:10) @ Forest and Wilderness 2,237 699,227 
Nevykes ART istas (X:8,Y:1) Mountainous 5,574 1,778,710 
Conflict (X:1,Y:2) Mountainous 1,115 295,153 
Tarosian Empire (X:1,Y:6) Multiple Terrain 3,151 753,822 
Evil Dome (X:4,Y:5) Mystical Lands 253 16,078 
Land of Xanth (X:3,Y:7) Mystical Lands 1,377 252,463 
Nalkalaakso (X:2,Y:10) Terra Form 2,299 511,322 
Draconis Centauri (X:10,Y:9) Forest and Wilderness 145 13,934 
Cuba (X:9,Y:2) Volcanic Inferno 250 16,339 
land of flecher (X:4,Y:3) Mountainous 152 13,286 


Total Sector Networth: 9,155,842


Game Help 
Money: 180,946 Power: 143,618 Population: 16,708 Networth: 786876 ";

$strings = explode("\n", $txt); 


foreach ($strings as $str) { 
    $res = preg_match("#([a-z0-9_]+)\s+\(([^\)]+)\)\s+@?([a-z\s]+)\s+([0-9]+(?:,[0-9]+)?)\s+([0-9]+(?:,[0-9]+)?)#i", $str, $matches); 
if ($matches[1]){
echo "$matches[1] ($matches[2])\t\t$matches[3] $matches[4] $matches[5]\n<BR>"; 
}
}


Nu weergeeft hij alleen de info waar het omgaat maar ook
Notice: Undefined offset: 1 in /var/www/htdocs/overig/sk.php on line 75
een paar keer boven de data en een paar keer eronder.
Hoe kan ik dat verwijderen, dus op een nette manier, nietgewoon Errors uitzetten

btw
The Sector Of: under 500k nw = 2x retals [Luminatx] (2:38)
Dan probeer ik die 2:38 er uit te vissen, maar er staan wel meer ( en : in de tekst iemand een hint in de goede richting? :)

[ Voor 5% gewijzigd door commeric op 05-01-2003 16:39 ]


Acties:
  • 0 Henk 'm!

  • commeric
  • Registratie: November 2002
  • Laatst online: 14-08 22:32
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//deel 1
$mainparts = explode("Kingdom Name (Sector Coords) Planet Type Land Networth Tactical", $txt); 
echo $mainparts[0]; //<---bovenste
echo "<br>++++++++++++++++++++++++++++++++++<BR>";
echo $mainparts[1];//<----de info waar het omgaat!

//deel 2
$locatie = explode("(", $mainparts[0]); 
echo "<BR>---------------<br>";
echo $locatie[0];
echo "<BR>";
echo $locatie[1];
echo "<BR>";
echo $locatie[2];

Deel 1 werkt goed, maar deel 2 opzich ook wel, alleen hier in:
The Sector Of: under 500k nw = 2x retals [Luminatx] (2:38)

kunnen ook ( voorkomen bijv
The Sector Of: under (wazaa) nw = 2x retals [Luminatx] (2:38)

dan werkt deel 2 dus niet...hoe los ik dit op?

Acties:
  • 0 Henk 'm!

Verwijderd

commeric2 schreef op 05 januari 2003 @ 16:37:
:D:D mijn ged8te gang klopte voor het eerst :D, dank jullie wel :D

ik ben nu zover, maar ik heb er wel vaker last van dat ie offset errors geeft als een array niet bestaat. HOe kan ik dat controleren?

Nu weergeeft hij alleen de info waar het omgaat maar ook
Notice: Undefined offset: 1 in /var/www/htdocs/overig/sk.php on line 75
een paar keer boven de data en een paar keer eronder.
Hoe kan ik dat verwijderen, dus op een nette manier, nietgewoon Errors uitzetten

btw
The Sector Of: under 500k nw = 2x retals [Luminatx] (2:38)
Dan probeer ik die 2:38 er uit te vissen, maar er staan wel meer ( en : in de tekst iemand een hint in de goede richting? :)

Je kunt sowieso controleren met is_Array ( $var ) wat een bool teruggeeft.

Als je de code netter wil maken m.b.t. die offset waarschuwingen dan zul je toch echt het relevante stuk code moeten geven ;) (Dus ook regel 75 )
Pagina: 1