Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to split twice the file, one for the lines, one for the countries.</p> <p>Also, since your "country header" is always the first item of each row, you do not need to check using <code>strlen</code>. Just shift out the first item of each row set: that one is the header, the following ones are the countries.</p> <p>Something like this.</p> <p>Note that in your code there is a syntax error in the <code>echo</code> that outputs the value, the <code>&gt;</code> symbol is actually <em>outside</em> the quotes.</p> <pre><code>function list_countries($id,$name=null,$result=null){ $countries = 'countries.txt'; $selected = ''; $text = '&lt;select name="'.$name.'" id="'.$id.'"&gt;'; $text .= '&lt;option disabled&gt;ﻁﺎﻠﺑ ﺎﻠﻏﺩ&lt;/option&gt;'; if(file_exists($countries)){ if(is_readable($countries)){ $list = file($countries); foreach($list as $item){ $item = trim($item); $opts = explode('|', $item); // The first item is the header. $text .= "&lt;option disabled&gt;$opts[0]&lt;/option&gt;"; array_shift($opts); foreach($opts as $opt) { $value = sql_safe($opt); $text .= '&lt;option'; if($value == $result) $text .= ' selected="selected"'; $text .= ' value="'.$value.'"'; $text .= '&gt;'.$value."&lt;/option&gt;\n"; } } }else{ $text .= "The file is not readable!"; } }else{ $text .= "The file does not exist!"; } $text .= '&lt;/select&gt;'; return $text; } </code></pre> <p>I have slightly modified your code so that the function actually <em>returns</em> the text to be output instead of echoing it; this makes for more reusability. To make the above function behave as yours did, just replace the <code>return</code> with</p> <pre><code> echo $text; } </code></pre> <p>and you're good.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload