Jump to content
php.lv forumi

PHP un Faili


Digital-X

Recommended Posts

Mans.txt

Iespeeja1
Iespeeja2
Kauktas te
un arii te

lai izrukaatu rindinjas vajag:

 

$mans_var = file("Mans.txt");

echo "Shii ir ".$mans_var[0];

echo "Bet te ir: ".$mans_var[2];

 

Bet ko dariit lai ieraxtiitu noteiktajaa rindinjaa? :blink:

...un veel par masiiviem -

 

$arrays_from_explode = explode(",",$fp);
$my = array($arrays_from_explode);
if  ($_POST['blah'] = $my){ 
echo "Kautkas te" 
}
else { 
echo "nekaa te nav :P"
}

..shitaads skriptijs nestraadaa, es gribu, lai vinsh nolasa sho failu saliek pa arrayiem visu kas aiz "," un peec tam paarbauda vai posts sakriit ar kaadu no arrayiem.

Edited by Digital-X
Link to comment
Share on other sites

$my = explode(",",$fp);
for($i=0;$i<=count($my);$i++) {
if  ($_POST['blah'] = $my[$i]){ 
$ir = TRUE;
}
}

if ($ir == TRUE) {
echo 'te kaut kas ir ';
}
else {
echo 'te kaut kaa nav;D';
}

 

Nu neesu testeejis, bet domaaju ka jaaiet!

 

Btw shitais ir diezgan pagarsh, imho vareetu arii iisaak!

 

Kaut gan, tiko padomaaju ja $fp = file('mans.txt'); tad tur iznaak pilniigs bulshits.

Ieprieksh nebiju ieskatijies..

 

Tad nu vareetu buut ~ taa (atkal neesu notesteejis, slinkums mani maac)

 

<?php
$fp = file('mans.txt');
for($f=0;$f<=count($fp);$f++) {
$my = explode (",",$fp[$f]);
for ($i=0;$i<=count($my);$i++) {
if ($_POST['blah'] == $my[$i]) {
$ir = TRUE;
}
}
}
if ($ir==TRUE) {
echo 'ir, ir, viss kedaaa';
}
else {
echo 'aij, blje nav;(';
}
?>

Edited by rnc
Link to comment
Share on other sites

Es gan pilniibaa visu nesapratu no pirmaa posta (arii no otraa) bet nu meegjinaashu atbildete pa gabalinjam..

 

Lai noskaidortu vai veertiba ir arrayaa vinsh nav ar ciklu jaapaarbauda.. Eksistee in_array() http://lv.php.net/in_array

 

Proti ja $my ir arrays tad

if(in_array($_POST['blah'],$my)) { ir; } else { nav; }

 

 

 

$arrays_from_explode = explode(",",$fp);

$my = array($arrays_from_explode);

 

Shis te ir gauzhaam nepareizi..

 

1. Balstoties uz pirmo scripta fragmentu $fp = file('mans.txt'); $fp jau tiek izveidots kaa masiivs (arrays) kursh satur katru faila rindinju jaunaa masiiva elementaa.. explode() nepiecieshams strings

Liidz ar to $fp = file_get_contents('mans.txt');

 

2. Funkcija explode() atgriezh masiivu tapeec veelreiz likt funkcijaa array() masiivu nav pareizi..

Link to comment
Share on other sites

bet kaa tad lai ieraxta failaa, noteiktaa rindinjaa :blink: :huh: ?

 

mansfails.txt

rinda1
rinda2
rinda3
rinda4

 

Un es caur formu gribu samainiit, ka piemeeram row[0] (kuraa rindaa) buus raxtiits "mana jaunaa 1. rinda!"

 

Kautko jau atradu :) lai tiktu jaunaa rindinjaa ir jaaraxta \r\n

Edited by Digital-X
Link to comment
Share on other sites

peec kaada kriteerija tu noteiksi, kuraa rindaa tev to jauno rindu vajag?

vispirms tev buus jaanolasa fails un janosaka kruaa vietaa tu to gribi dariit un peec tam ar fseek jaaaiziet failaa uz to vieutu,kuraa tev vajag ierakstiit.

Link to comment
Share on other sites

atrdadu sho te.

<?php

 

$fp = fopen('somefile.txt');

 

// read some data

$data = fgets($fp, 4096);

 

// move back to the beginning of the file

// same as rewind($fp);

fseek($fp, 0);

 

?>

Laikam jaaliek shaadi...

$seeek = fseek($fp, 5);

fwrite($fp,$seeek)

un tad vinsh ieraxtiis tajaa 5 rindinjaa?

Link to comment
Share on other sites

īsti pareizi jau nav bet tomēr

 

 

 

 

<?php

$mans_var = file("Mans.txt");

$fp= fopen("Mans.txt","w");

$kuraa_rindinjaa = 2;

$ko_rakstit = "jaunaaa rindinja";

for ($i=0;$i<count($mans_var)+1;$i++)

{

if ($i != $kuraa_rindinjaa-1)

{

fwrite($fp,$mans_var[$i]);

}

else

{

fwrite($fp,$ko_rakstit."\r\n");

fwrite($fp,$mans_var[$i]);

}

}

 

 

fclose($fp);

?>

Link to comment
Share on other sites

×
×
  • Create New...