Jump to content
php.lv forumi

raivis

Reģistrētie lietotāji
  • Posts

    106
  • Joined

  • Last visited

Posts posted by raivis

  1. Kur kļūda...?

    Fatal error: Can't use function return value in write context in c:\www\unregister.php on line 4

    • unregister.php
      <?php
      $adreses=str_replace(array("\n","\r",' '),'',file_get_contents('adreses.txt'));
      $adreses=explode('|',$adreses);
      unset(array_search($meklejama,$adreses));
      $fh=fopen('adreses.txt','w');
      fwrite($fh,implode('|',$adreses));
      fclose($fh);
      ?>


    ???????????????????????????????????????

    if $meklejama = atrasta($adreses); {

    delete atrastais $meklejama;

    echo "Jūsu e-pasta adrese $meklejama veiksmīgi atreģistrēta";

    } else if $meklejama nav atrasta($adreses); {

    echo "Adrese nav reģisrēta sistēmā!";

    }

    ???????????????????????????????????????

  2. Arī mani agrāk tas ļoti, ļoti ieinteresēja> pēc apmeklētāja IP adresses noteikt lietotāja Pilsētu utt.

    Ceru, ka ar šo tev būšu atbildējis:

    <?php
    
    ###############################
    #   http://raivis.tk          #
    #   filename: Location.php    #
    ###############################
    
    require("ip2country.php"); #http://paste.php.lv/1415
    
    //        print "Client IP:       ".$myCliInf->getClientIP()."<br>";
    //        print "Client Hostname: ".$myCliInf->getClientHostname()."<br>";
    //        print "Client Country:  ".$myCliInf->getClientCountry()."<br>";
    //        print "Client Flag: ".$myCliInf->getClientFlag(SMALL)."<br>";
    //        print "Client Flag: ".$myCliInf->getClientFlagHTML(SMALL)."<br>";
    #         try with SMALL or BIG to change the size of the flag</a>
    
    $myCliInf = new ClientInfo;
    if ($myCliInf->getClientCountry()) {
    print "You are from  <b>".$myCliInf->getClientCountry()."</b>.";
    } else {
      print "unknow";
    }
    ?>

  3. Kādam vajadzētu izskatīties reģistācijas formas kodam, kur PAROLEI jābūtu 7 - 10 simbolu garai, tā nedrīkstētu saturēt mīkstinājuma zīmes/garumzīmes ?

     

    //<input type="password" name="password" maxlength="10">
    if $password = no 7-10 simboliem, bez mīkstinājuma zīmēm!; { 
      $password = htmlspecialchars(strtolower(stripslashes($password)));
           $file = join("", file($data));
           $fp = fopen($data, "w");
                   fputs($fp, "$password|\r\n");
                   fputs($fp, $file);
           fclose($fp);
     echo "Ok!";
    } else {
     echo "Parolei jābūt 7 - 10 simbolu garai, bez mīkstinājuma zīmēm/garumzīmēm!";
    }

  4. :huh: Paldies par atbildi, bet tai seko vēl viens jautājums..

     

    KUR KĻŪDA!? :(

     

    ///////file:data.txt/////////

    Janis|18|[email protected]|

    Peteris|21|[email protected]|

    Juris|51|[email protected]|

    Olga|18|[email protected]|

    Janis|11|[email protected]|

    ///////end file//////////////

     

    :blink: Startējot skriptu, no faila data.txt izdzēšas ne tikai rindiņas, kurās $name='Janis', bet beidzamais '|' un atkāpes.

    Atkārtoti startējot skriptu, failā data.txt rodas tīrais gļuks.

    Kādēļ? Ja man vajadzīgs, lai izdzēstos tikai rindiņa + tās atkāpe, kuras $name='Janis'.

    $fileData = file("data.txt");
    $personList = array();
    foreach ($fileData as $row){
    list($name, $age, $email) = explode('|', $row);
    $personList[] = array('name' => $name, 'age' => $age, 'email' => $email);
    }
    
    // 1. punkts
    // No faila "data.txt" izdzēst tās rindiņas, kurās $name=="Janis";
    foreach ($personList as $key => $person){
    if ($person['name'] == 'Janis') {
      unset($personList[$key]);
    }
    }
    
    $f = fopen('data.txt', 'w');
    foreach($personList as $row) {
      fwrite($f, implode('|', $row));
    }
    fclose($f);

     

    $fileData = file("data.txt");
    $personList = array();
    foreach ($fileData as $row){
    list($name, $age, $email) = explode('|', $row);
    $personList[] = array('name' => $name, 'age' => $age, 'email' => $email);
    }
    
    // 2. punkts
    // Ja faila "data.txt" $name=="Janis" { $name vērtību rename/pārsaukt par "JanisOzols"; }
    foreach ($personList as $key => $person){
    if ($person['name'] == 'Olga'){
    $personList[$key] = array('name' => 'JanisOzols', 'age' => $person['age'], 'email' => $person['email']);
    }
    }
    
    $f = fopen('data.txt', 'w');
    foreach($personList as $row) {
      fwrite($f, implode('|', $row));
    }
    fclose($f);

    Paldies vēlreiz!

  5. pienjemsim man ir fails "data.txt" ar mainiigajiem { list($name,$age,$email) = explode("|", $file[$line]); }

    ///////file:data.txt/////////

    Janis|18|[email protected]|

    Peteris|21|[email protected]|

    Juris|51|[email protected]|

    Olga|18|[email protected]|

    Janis|11|[email protected]|

    ///////end file//////////////

     

    ///////file:users.php///////

    <?php
    $file = file("data.txt");
    $totalLines = sizeof($file);
    for($line = 0; $line < $totalLines; $line++){
    if("//" != substr($file[$line], 0, 2)){
      @list($name,$age,$email) = explode("|", $file[$line]);
      $name = ucfirst($name);
         $string = $name.",".$age.",".$email."<br>";
         echo $string;
    }
    }
    ?>

    ///////end file//////////////

     

    Kaads izskatiitos kods, ja programmai liktu:

    1. no faila "data.txt" izdzeest taas rindinjas, kuraas $name=="Janis";

    2. ja faila "data.txt" $name=="Janis" { $name veertiibu rename/paarsaukt par "JanisOzols"; }

    3. izskaitiit, cik reizes failaa "data.txt" $name=="Janis";

    4. no faila "data.txt" print/apluukot taas rindinjas $name,$age,$email veertiibu, kuraa $name=="Pereris";

×
×
  • Create New...