Solved

php using preg_split

Posted on 2011-10-01
2
309 Views
Last Modified: 2012-05-12
hello there,
how can I switch from split into preg_split with the function bellow
function loadAvg() {
	$load = exec("uptime");
	$load = split("load average:", $load);
	$load = split(", ", $load[1]);
	$load = $load[0];
	return $load;
}

Open in new window

0
Comment
Question by:XK8ER
  • 2
2 Comments
 
LVL 15

Expert Comment

by:ncoo
ID: 36895769
It would be simpler and faster using preg_match, see code:
0
 
LVL 15

Accepted Solution

by:
ncoo earned 500 total points
ID: 36895770
They I have now attached, sorry.
<?php
function loadAvg() {
	$load =  '08:44:05 up 42 days, 19:07,  1 user,  load average: 0.10, 0.17, 0.17';;//'exec("uptime");
	preg_match("/load average: ([^,]*?),/", $load,$m);
	return $m[1];
}
var_dump(loadAvg());

Open in new window

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question