Solved

php using preg_split

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 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

14 Experts available now in Live!

Get 1:1 Help Now