Change the order of characters in a word


Keywords:php 


Question: 

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"


2 Answers: 

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



Try to something like this...

$string = '0100455_LM_Izaguirre';
$String1 = explode('_', $string);
echo $String1['1']."_".$String1['0'];