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? 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) 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
Archived
This topic is now archived and is closed to further replies.