Jump to content

str_replace using wildcards


PhillFernandes

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/223562-str_replace-using-wildcards/
Share on other sites

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) {...}

Archived

This topic is now archived and is closed to further replies.

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