koolaidman52 Posted January 22, 2007 Share Posted January 22, 2007 I'm helping a freidn out with a website for our school basketball team and we recently ran into a problem. I rushed in thinking that with my superior knowledge of all things php I would be able to solve any complex error he may have, but I can't figure out the proper way to use preg_replace() in this situaition (or if I need to use it at all).[code]$blah = $_SERVER['REQUEST_URI'];// $blah is /knights%20basketball/varsity/footer.php$blah = str_replace("/footer.php", "", $blah);// $blah is now /knights%20basketball/varsity //the following line of code is the problem i can't figure out what to put as the first argument.$blah = preg_replace('', '$1', $blah);// the /knight%20basketball/ changes so I can't just have it search and remove that.// $blah should now just be varsity// but it isn'techo $blah;[/code]please dont direct me to the php manual that didn't helpthanks for the help Link to comment https://forums.phpfreaks.com/topic/35278-preg_replace-help/ Share on other sites More sharing options...
redbullmarky Posted January 22, 2007 Share Posted January 22, 2007 take a look at [url=http://www.php.net/preg_replace]preg_replace[/url] in the manual.just kidding.what are you trying to match exactly? can you be a little more specific of what you're trying to do?cheers Link to comment https://forums.phpfreaks.com/topic/35278-preg_replace-help/#findComment-166734 Share on other sites More sharing options...
koolaidman52 Posted January 22, 2007 Author Share Posted January 22, 2007 well i'm getting the uri of the file which turs out to be "/knights%20basketball/varsity/footer.php" in my example. i want that cut down to "varsity" Link to comment https://forums.phpfreaks.com/topic/35278-preg_replace-help/#findComment-166736 Share on other sites More sharing options...
effigy Posted January 22, 2007 Share Posted January 22, 2007 If it's always going to be in that position:[code]<?php $string = "/knights%20basketball/varsity/footer.php"; list(,,$var) = explode('/', $string); echo $var;?>[/code] Link to comment https://forums.phpfreaks.com/topic/35278-preg_replace-help/#findComment-166746 Share on other sites More sharing options...
koolaidman52 Posted January 22, 2007 Author Share Posted January 22, 2007 aha, hadn't even thought of thatworks great, thanks Link to comment https://forums.phpfreaks.com/topic/35278-preg_replace-help/#findComment-166749 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.