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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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