Jump to content

booxvid

Members
  • Posts

    32
  • Joined

  • Last visited

Everything posted by booxvid

  1. You can draw it or CSS would be a good help for you.
  2. I just want my program to print those array until the period exist. <?php $filename = 'txt_files/read_this.txt'; $file_handle = file($filename); for($i=0;$i<count($file_handle);$i++) { if($file_handle[$i]=="."){ break; } else{ echo $file_handle[$i]; } } //fclose($file_handle); ?> here's the content of my text file. this your queen nice doll . you are it should stop reading the file when the loop meets '.' or the period i mean. but it still print out the "you are" words .. I already use the break statement, bu still...
  3. this is my main code <?php include 'qwerty.php'; $words = array(); $order = array('q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m'); $key = array(); //for added val keys $abc = array ("a","b","c","d"); $text = "class top clone house apple blue"; $words = explode(" ",$text); $flag =""; for($i=0,$j=count($words);$i<count($words);$i++,$j--){ $add_value = 0; $next_word = $words[$i]; $fletter_nextword = Qwerty::get_first_letter($next_word); echo $fletter_nextword."<br/>"; if(!in_array($fletter_nextword,$order)){ echo "there's a number in a string"; $flag="FALSE"; break; } else{ $key_nextword = Qwerty::get_key($fletter_nextword,$order); echo $key_nextword.'<br/>'; if(in_array($key_nextword,$key)){ $key[$i] = $key_nextword.'b'; $flag = "TRUE"; } else{ $key[$i] = $key_nextword.'a'; $flag = "TRUE"; } } } if($flag!="FALSE"){ $words_key = array_combine($key,$words); ksort($words_key); foreach ($words_key as $key => $value){ echo $value.' '.$key.'</br>'; } } ?> the problem is, when I'm trying to sort these words by the assigned array, what happen is EXAMPLE: close and class does have same first letter which means, I assigned it already that if the word starts with letter c the key should be is 21 this is according to the qwerty order what happen with the words close and class... close will not be included in the printed words in a sort out qwerty order /: how to put up extra added key with the same key in it?
  4. Thanks! I'm almost done with this sorting work. function get_key($the_letter,$order){ $key=""; for($i=0;$i<count($order);$i++){ if($the_letter==$order[$i]){ $key = $i; break; } } return $key; } got one last question: is my function correct? by when I loop in with the array of qwerty, together the first word that I've got is this the right way in stopping a for loop?
  5. Oh sorry, I've already updated my codes. <?php // include 'qwerty.php'; $words = array("one,two,free"); $order = array('q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m'); $key = array(); $text = "one two free"; $words = explode(" ",$text); // for($i=0;$i<count($words);$i++){ // $next_word = $words[0]; echo $next_word; $temp = array(); echo $temp[0]; //$fletter_nextword = get_first_letter($next_word); // $key_nextword =get_key($fletter_nextword,$order); // // $key[0] = $key_nextword; // echo $key[0]; // // } // $words_key = array_combine($key, $words); // ksort($words_key); // // foreach ($words_key as $key => $value){ // // echo $value.'</br>'; // } function get_first_letter($this_word){ $temp = explode(' ',$this_word); return $temp[0]; } function get_key($the_word,$order){ $key=""; for($i=0;$i<count($order);$i++){ if($the_word==$order[$i]){ $key = $i; break; } } return $key; } ?> my problem right now is how to get the first letter of a string.
  6. This program is to sort words into qwerty order. <?php // include 'qwerty.php'; $words = array("one,two,free"); $order = array('q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m'); $key = array(); $text = "one two free"; $words = explode(" ",$text); for($i=0;$i<count($words);$i++){ $next_word = $words[$i]; $fletter_nextword = get_first_letter($next_word); $key_nextword =get_key($fletter_nextword,$order); $key[$i] = $key_nextword; } $words_key = array_combine($key, $words); ksort($words_key); foreach ($words_key as $key => $value){ echo $value.'</br>'; } function get_first_letter($this_word){ $temp = explode(' ',$this_word); return $temp[0]; } function get_key($the_word,$order){ $key=""; $i=0; do{ if($the_word==$order[$i]){ $flag = "TRUE"; $key = $i; } else{ $flag = "FALSE"; } $i++; }while($flag=="FALSE"); return $key; } ?> It says : Notice: Undefined offset: 26 in C:\xampp\htdocs\OOP_SYSTEM\qwerty sort\sort_qwerty.php on line 48
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.