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