ERuiz Posted October 23, 2007 Share Posted October 23, 2007 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 https://forums.phpfreaks.com/topic/74445-solved-splitting-variable-into-2-variables-then-creating-a-new-variable/ Share on other sites More sharing options...
PHP_PhREEEk Posted October 23, 2007 Share Posted October 23, 2007 See this: http://us.php.net/manual/en/function.preg-replace.php If you actually want to split the variable in certain cases, see also: http://us.php.net/manual/en/function.preg-split.php PhREEEk Link to comment https://forums.phpfreaks.com/topic/74445-solved-splitting-variable-into-2-variables-then-creating-a-new-variable/#findComment-376110 Share on other sites More sharing options...
only one Posted October 23, 2007 Share Posted October 23, 2007 check the str_replace() manual Link to comment https://forums.phpfreaks.com/topic/74445-solved-splitting-variable-into-2-variables-then-creating-a-new-variable/#findComment-376113 Share on other sites More sharing options...
thebadbad Posted October 23, 2007 Share Posted October 23, 2007 <?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 Link to comment https://forums.phpfreaks.com/topic/74445-solved-splitting-variable-into-2-variables-then-creating-a-new-variable/#findComment-376117 Share on other sites More sharing options...
ERuiz Posted October 23, 2007 Author Share Posted October 23, 2007 <?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 https://forums.phpfreaks.com/topic/74445-solved-splitting-variable-into-2-variables-then-creating-a-new-variable/#findComment-376292 Share on other sites More sharing options...
d.shankar Posted October 23, 2007 Share Posted October 23, 2007 Do click topic solved ! Thanks Link to comment https://forums.phpfreaks.com/topic/74445-solved-splitting-variable-into-2-variables-then-creating-a-new-variable/#findComment-376300 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.