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

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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