Abafowunelwa

NguAndy Harris

Ukuba usebenza nedatha emiselweyo yi-PHP yenkqubo ye-HTML5 kunye ne-CSS3, unokufuna ukuzifundela ngokwakho idatha ye-CSV. Akunzima kakhulu ukwenza. Jonga le khowudi ilandelayo ye-ReadContactCSV.php:

Ukujonga kuqala ifayile ye-php ye-HTML kunye ne-CSS.



 readContactCSV.php First Last email phone HERE; $data = file('contacts.csv'); foreach ($data as $line){ $lineArray = explode('t', $line); list($fName, $lName, $email, $phone) = $lineArray; print << 

Kule nkqubo, imixholo yefayile ye-CSV yafundwa kwaye yaboniswa kwitafile ye-HTML. Ayifani ngendlela eyoyikisayo kunokufunda nayiphi na enye ifayile yokubhaliweyo, kodwa kukho ezinye iinguqulelo ezintsha.

  1. Phrinta isihloko setafile.

    Kulula kakhulu ukuprinta ngesandla isihloko setafile ngamagama endawo. I-heredoc elula iya kuwenza umsebenzi.

    print <<< HERE HERE;
    First Last email phone
  2. Layisha idatha kuludwe.

    I-PHP inesixhobo esimangalisayo esibizwa ngokubaifayile. Lo msebenzi uthatha igama lefayile njengekuphela kwegalelo lalo. Emva koko ivula le fayile kwaye ibeka yonke imixholo kuluhlu, ibeka umgca ngamnye kwinto yayo kuludwe. Akukho sidingo sokwenza isikhombisi sefayile, okanye ukuvula okanye ukuvala ifayile. Kulo mzekelo, imixholo ye-abafowunelwazilayishwe kuludwe olubizwaIdatha yedatha.

    $data = file('contacts.csv');
  3. Sebenzisa iyanganyeloop ukunyathela imixholo.

    Ngoku ungahamba ngokuqulethwe yifayile ngokululayanganyeloop. Umgca wangoku ubekwe kuguquguquko olubizwa ngokuba$ umgca.

    foreach ($data as $line){
  4. Dlulisa umgca ngamnye kuludwe lwawo.

    Kufuneka uwuthande umsebenzi onegama elinogonyamelo, ngakumbi xa uluncedo lokwenene. Sebenzisa idubulaukuyalela ukwahlula umgca kumacandelo alo.

     $lineArray = explode('t', $line);
  5. Sebenzisa iuluhlu ()ukusebenza ukugcina into nganye yoluhlu kuluhlu lwayo.

    Unokusebenzisa nje uluhlu, kodwa kulula ukudlulisa idatha ubuyisele kumagama afanayo owasebenzisileyo xa usenza inkqubo. Inkqubo ye-uluhlu ()ukwakha kwenza kanye loo nto. Yondle ngeqela lamagama aguqukayo kwaye unike uluhlu kuwo, kwaye ngoku into nganye yoluhlu iya kwabelwa umahluko ohambelana nayo.

     list($fName, $lName, $email, $phone) = $lineArray;
  6. Phrinta izinto eziguquguqukayo kwilayini yetafile ye-HTML.

    Zonke izinto eziguquguqukayo zilunge kakuhle kwitafile ye-HTML, ke vele uprinte umqolo wangoku wetafile.

     print <<< HERE $fName $lName $email $phone HERE;
  7. Coca izinto zakho zokudlala.

    Kukho ukugcinwa kwekhaya okuncinci ukwenza. Gqibezela iluphu kwaye uvale itafile ye-HTML. Akukho sidingo sokuvala ifayile kuba oko kwenziwa ngokuzenzekelayo yifayile ye-ifayile ()umsebenzi.

     } // end foreach //print the bottom of the table print ' n';

Ezi ndlela zimfutshane - indlelaifayile ()function kunyeuluhlu ()-Yenza kube lula kakhulu ukusebenza ngedatha ye-CSV. Kungenxa yeso sizathu le nto olu hlobo lwedatha ludumile kwiingxaki zedatha esisiseko.

Inkqubo ye-uluhlu ()Umsebenzi usebenza kuphela kulungelelwaniso lwamanani alungelelanisiweyo kwaye uthatha ukuba isalathiso soludwe luqala0. Ukuba ufuna ukusebenzisa iuluhlu ()sebenza ngokudibanisa uluhlu, jikeleza uluhlu olwahlukileyo kunyeuluhlu lweempawu ()umsebenzi. Ngokobuchwephesha,uluhlu ()ayisiwo umsebenzi kodwa lulwimi olwakhiweyo.

Inkqubo ye-ifayile ()Umsebenzi unomdla, kodwa awulunganga kuzo zonke iimeko. Kuhle kakhulu ukuba ubungakanani befayile buncinci, kodwa ukuba uzama ukulayisha kwifayile enkulu kakhulu, uya kubaleka kwimemori. Umgca ngendlela yexesha elisetyenziswe kwi-readContact.php ayinangxaki kuba kukho inani elincinci ledatha kwimemori ngalo naliphi na ixesha.

op 20 vs percocet

I-HTML purists ihlala ithanda ukuphuma xa ibona itafile ye-HTML. Kuyinyani ukuba iitafile ze-HTML zazikhe zaxhatshazwa ngendlela eyothusayo, kodwa oko akuthethi ukuba kufanelekile soze isetyenziswe.