[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] [PHP] Udskrive bogstav-række



Arkanoid wrote:
Hej

Jeg har gang i et projekt i PHP, dertil ønsker jeg at kunne udskrive en bogstavrække (med et link) med alle de bogstaver, der ikke er valgt.
Jeg har en string med valgte bogstaver ($foo) og ønsker derfor at undersøge om et bogstav findes i den. Spørgsmålet er, om der er en lettere måde at gøre det på end at skrive :


if (strpos($foo,"A") == 0){
$letters_to_write .= "<a href=\"bar.php?letter=A\" title=\"A\">A</a> | ";
}
if (strpos($foo,"B") == 0){
$letters_to_write .= "<a href=\"bar.php?letter=B\" title=\"B\">B</a> | ";
}


osv. for alle bogstaver i alfabetet.

Altså som ubrugte bogstaver i et Lykkehjulet-spil (eller hangman) eller lignende?


$mulige="abcd..."; // Fyld selv.
$valgte="c";
$udskrift='';

// Fjerner alle de brugte tegn ved at erstatte dem med ingenting.
$ubrugte=$preg_replace("/[{$valgte}]/",'',$mulige);

if(strlen($ubrugte)>0){
  for($i=0;$i<strlen($ubrugte);$i++){
    $b=$ubrugte{$i};
    $ud .= "<a href='bar.php?letter={$b}' title='{$b}'>{$b}</a> | ";
  }
}

Med venlig hilsen

Ole

 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *