PhillFernandes Posted January 6, 2011 Share Posted January 6, 2011 Hi, I think I have this right but I would like someone to verify that. function storageAmmount() { system('stat /web/'.$user."/ | grep Size: > /web/".$user."/log/storage"); $storage = fopen('/web/'.$user.'/log/storage'); $storage = str_replace('Size:', " ", $storage); $storage = preg_replace('Blocks:(((A-Z), a-z), 1-9)','',$storage) } This is the line in the text file: Size: 4096 Blocks: 8 IO Block: 4096 directory I am trying to get just the numeric value the proceeds "Size: ", the word Size: and everything else is usless to me. I am mainly looking at the preg_replace. Is it just me or is regex a tad bit confusing? Any thoughts. Thanks for any help in advance. Cheers!, Phill Quote Link to comment https://forums.phpfreaks.com/topic/223562-str_replace-using-wildcards/ Share on other sites More sharing options...
.josh Posted January 6, 2011 Share Posted January 6, 2011 function storageAmmount() { system('stat /web/'.$user."/ | grep Size: > /web/".$user."/log/storage"); $storage = fopen('/web/'.$user.'/log/storage'); preg_match('~Size:\s*(\d+)~i',$storage,$match); return $match[1]; } dunno where you are getting that $user var though... if it's a global var you need to first do global $user; or else you need to pass it to the function function storageAmount($user) {...} Quote Link to comment https://forums.phpfreaks.com/topic/223562-str_replace-using-wildcards/#findComment-1155662 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.