Jump to content

[SOLVED] Splitting variable into 2 variables then creating a new variable


ERuiz

Recommended Posts

Hello all,

 

Here is the problem I have. How can I take $variable1 and split it into 2 variables IF a certain criteria is met. For example:

 

$variable1 = "AA1234"

 

The above variable has a VALID value, so it's passed AS IS and nothing is done to it.

 

$variable1 = "AAL1234"

 

The above variable has AAL in it but this is NOT allowed. How can I take this variable and turn it into "AA1234" (without quotes obviously). In other words, every time $variable1 has a AAL in it, I need to change that into AA.

 

Thanks for any help on this.

 

Regards,

 

ERuiz

<?php
if (preg_match("/AAL/", $variable1)) {
$bits = explode("AAL", $variable1);
$variable1 = 'AA'.$bits[1];
}
?>

 

EDIT: I see this isn't the most efficient way to do it, but it works :)

 

This did the trick! Thanks a million, my friend.

 

Regards,

 

ERuiz

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.