Jump to content

flip flop extensions


fordgt72

Recommended Posts

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

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

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

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.