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. Link to comment https://forums.phpfreaks.com/topic/174803-flip-flop-extensions/ 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? Link to comment https://forums.phpfreaks.com/topic/174803-flip-flop-extensions/#findComment-921233 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. Link to comment https://forums.phpfreaks.com/topic/174803-flip-flop-extensions/#findComment-921326 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 Link to comment https://forums.phpfreaks.com/topic/174803-flip-flop-extensions/#findComment-921334 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. Link to comment https://forums.phpfreaks.com/topic/174803-flip-flop-extensions/#findComment-921340 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.