php - Substr Logic Function -


i want ask substr() function. have code this:

<?php     $word = 'diriku';     $word2 = $word;     //first condition     if ( (substr($word,-3)=="kah") or (substr($word,-3)=="lah") or (substr($word,-3)=="pun") or (substr($word,-3)=="nya")) {     $word2 = substr($word,0,-3); }     //second condition else if( (substr($word,-2)=="ku") or (substr($word,-2)=="mu") ) {     $word2 = substr($word,-2); }     echo $word2;     echo "<br />";     echo $word; ?> 

result must : diri don't know why result dir. opinion substr cut word @ first condition although it's true or false.

so know how logic compare substr function if first condition true, pass else, , if cond false, continue else, not true.

sorry mess explanation.. don't know how describe clearly.

 <?php         $word = 'songsangkukah';         $word2 = $word;          if ( (substr($word,-3)=="kah") or (substr($word,-3)=="lah") or (substr($word,-3)=="pun") or (substr($word,-3)=="nya"))         {            $word2 = substr($word, 0 , -3);         }          if((substr($word2,-2)=="ku")or(substr($word2,-2)=="mu"))         {             $word2 = substr($word2 , 0 , -2);         }          echo $word2;         echo "<br />";         echo $word;     ?> 

here go. required output.


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -