Search code examples
phpwordsstrpossuffix

Change the order of characters in a word


I have the following nomenclature:

0100455_LM_Izaguirre

I need to change to be as follows:

LM_0100455

The idea would be to first put the suffix "LM", then the code "0100455" and erase everything else. The problem is that the suffix is not unique, it can vary "LM, LI, AQ"


Solution

  • Try this:

    $str = '0100455_LM_Izaguirre';
    $data = explode("_", $str);
    
    // where:
    // $data[0] = 0100455;
    // $data[1] = LM;
    // $data[2] = Izaguirre;
    
    
    $str = $data[1].'_'.$data[0];
    
    echo $str;
    

    // Output : LM_0100455