fordgt72 Posted September 19, 2009 Share Posted September 19, 2009 Hi, How could I flip flop the below extensions? $s1 = '13.61sd'; $s2 = '25.21ed'; Every so often I'll need to flip the extensions like so.. $s1 = '13.61ed'; $s2 = '25.21sd'; I thought I could do an "if and" statement and then a str_replace but I'm missing something or it's not the proper solution. if ($s1==('/^[0-9]{2}.[0-9]{2}sd/') && $s2==('/^[0-9]{2}.[0-9]{2}ed/')) { $s1A=str_replace('sd','ed',$s1); $s2A=str_replace('ed',sd',$s2); } Thanks for any help I appreciate it. Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 19, 2009 Share Posted September 19, 2009 Is that code not working? Idea is great, looks ok. What is it not doing? Quote Link to comment Share on other sites More sharing options...
fordgt72 Posted September 19, 2009 Author Share Posted September 19, 2009 Thanks for the reply. If I add an echo $s1A at the end I get no output. <? $s1 = '13.61sd'; $s2 = '25.21ed'; if ($s1==('/^[0-9]{2}.[0-9]{2}sd/') && $s2==('/^[0-9]{2}.[0-9]{2}ed/')) { $s1A=str_replace('sd','ed',$s1); $s2A=str_replace('ed',sd',$s2); } echo $s1A; ?> I think I'm missing something in the if statement. Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 19, 2009 Share Posted September 19, 2009 I am not good with expressions, but try this <? $s1 = '13.61sd'; $s2 = '25.21ed'; if (preg_match('/^[0-9]{2}.[0-9]{2}sd/',$s1) && preg_match('/^[0-9]{2}.[0-9]{2}ed/',$s2)) { $s1A=str_replace('sd','ed',$s1); $s2A=str_replace('ed',sd',$s2); } echo $s1A; ?> if not, try asking in http://www.phpfreaks.com/forums/index.php/board,43.0.html Quote Link to comment Share on other sites More sharing options...
fordgt72 Posted September 19, 2009 Author Share Posted September 19, 2009 That didn't work either. Thanks for your help. I'll give the link you supplied a try. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.