Solved

php using preg_split

Posted on 2011-10-01
2
315 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

617 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