All4172 Posted April 27, 2007 Share Posted April 27, 2007 What I'm wanting to do is a statement like: $file = "/path/www/mydir/3429438.php"; if ($file == "/path/www/mydir/"){ $file = "/path/www/NEWmydir/3429438.php;} Quesiton is what regular expression in the if statement so it'll search /[0-9].php and how to take that filename and apend it on the new $file if the instance exists. Ideas? Quote Link to comment https://forums.phpfreaks.com/topic/48863-solved-question-about-regular-expressions/ Share on other sites More sharing options...
btherl Posted April 27, 2007 Share Posted April 27, 2007 Try this: if (preg_match('|/([0-9]+)\.php$|', $file, &$matches) === 1) { print "Matched {$matches[1]}\n"; } Then you can use $matches[1] to construct your new path (if all you want to do is replace mydir with NEWmydir) Quote Link to comment https://forums.phpfreaks.com/topic/48863-solved-question-about-regular-expressions/#findComment-239479 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.