Solved

php using preg_split

Posted on 2011-10-01
2
306 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now