Iets ophalen van txt

Gestart doorDylan6 reacties43 weergaven

7 berichten · pagina 1 van 1

Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Hoi,
Ik heb een txt bestand en daar staat dit in:

code: 1, naam: piet, achternaam: regenwater
code: 2, naam: jan, achternaam: plasje


nu wil ik met PHP die namen ophalen.. dus heb ik hier een script:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]code[/COLOR][COLOR= #007700]]) {
   
}[/COLOR]
?>


en nu loop ik vast, ik heb dus in de url bijv. ?code=2 dan moet er jan plasjekomen te staan hoe?

ik heb al gekeken op php.net bij fread(); maar ik snap het niet helemaal
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Is het niet zinvoller om een database te gebruiken?
0
Berichten
1.871
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Zoiets?

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]code[/COLOR][COLOR= #007700]])){[/COLOR]
[COLOR= #0000BB]$code[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]code[/COLOR][COLOR= #007700]]];[/COLOR]
[COLOR= #0000BB]$txt[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/file_get_contents"]file_get_contents[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"txt.txt"[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$txt[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/explode"]explode[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"code"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$txt[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$txt[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$code[/COLOR][COLOR= #007700]];
}[/COLOR]
?>


toevoeging op 27 augustus 2012, 16:33:53:
En zoals Aarclay ookal zegt, een database is hiervoor veel handiger.
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Hmm, nee dan krijg ik een witte pagina. Wat wel werkt is:

[COLOR= #0000BB]<?php
$data[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/file_get_contents"]file_get_contents[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"txt.txt"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/list"]list[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$code[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$naam[/COLOR][COLOR= #007700]) =[/COLOR] [URL="http://www.php.net/explode"]explode[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]","[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$code[/COLOR][COLOR= #007700];[/COLOR] 
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$naam[/COLOR][COLOR= #007700];[/COLOR]
?>


txt bestand;
1,piet
2,jan

alleen nu nog van ?code=2

dat ie dan alleen jan ophaalt en nu piet

toevoeging op 27 augustus 2012, 16:53:03:
Al opgelostbiggrin
[COLOR= #0000BB]<?php
$data[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/file_get_contents"]file_get_contents[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"txt.txt"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/list"]list[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$code[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$naam[/COLOR][COLOR= #007700]) =[/COLOR] [URL="http://www.php.net/explode"]explode[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]","[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$code[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$code[/COLOR][COLOR= #007700];[/COLOR] 
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$naam[/COLOR][COLOR= #007700]; 
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]er is een fout opgetreden![/COLOR][COLOR= #007700];
}[/COLOR]
?>
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dylanh schreef:
Hmm, nee dan krijg ik een witte pagina. Wat wel werkt is:

[COLOR= #0000BB]<?php
$data[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/file_get_contents"]file_get_contents[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"txt.txt"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/list"]list[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$code[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$naam[/COLOR][COLOR= #007700]) =[/COLOR] [URL="http://www.php.net/explode"]explode[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]","[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$code[/COLOR][COLOR= #007700];[/COLOR] 
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$naam[/COLOR][COLOR= #007700];[/COLOR]
?>
txt bestand;
1,piet
2,jan

alleen nu nog van ?code=2

dat ie dan alleen jan ophaalt en nu piet

toevoeging op 27 augustus 2012, 16:53:03:
Al opgelostbiggrin
[COLOR= #0000BB]<?php
$data[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/file_get_contents"]file_get_contents[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"txt.txt"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/list"]list[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$code[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$naam[/COLOR][COLOR= #007700]) =[/COLOR] [URL="http://www.php.net/explode"]explode[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]","[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$data[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$code[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$code[/COLOR][COLOR= #007700];[/COLOR] 
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$naam[/COLOR][COLOR= #007700]; 
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]er is een fout opgetreden![/COLOR][COLOR= #007700];
}[/COLOR]
?>


Als je dan 1.000.000 codes hebt dan moet die alles aflopen...

Beter inderdaad in database opslaan. Of iets met preg_match doen. En niet ophalen met file_get_contents, beter met cURL. Maar er bestaan nog beter manieren om het op te halen aangezien het op je eigen server staat.
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Waarom cURL?

naja, het is inderdaad beter om om het in een database op te slaan alleen is MySQL heel traag bij mij.
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dylanh schreef:
Waarom cURL?

naja, het is inderdaad beter om om het in een database op te slaan alleen is MySQL heel traag bij mij.
cURL is sneller als file_get_contents. En niemand heeft er last van dat MySQL bij JOUW traag gaat, toch?
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren