small problem i think

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

<?php

preg_match('#md\d\s*?\:\s*?active.*?((hd\w\d\[\d])\s*?)+?\d+?#is', $str, $matches);

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

hward wrote:how do i return the "[UU]" out of

Personalities : [raid1] read_ahead 1024 sectors md0 : active raid1 hde1[1] hdg1[0] 39078016 blocks [2/2] [UU] [======>..............] resync = 34.9% (13670876/39078016) finish=41.0min speed=10324K/sec unused devices:

it returns UU or _U or U_
hward, I hope you don't mind me replying here..

Code: Select all

<?php
preg_match('#(\[[^]]+?])\s*?\[[^]]+?]\s*?resync#is',$str,$matches);
?>
you need to do some research into regexes...
hward
Forum Contributor
Posts: 107
Joined: Mon Apr 19, 2004 6:19 pm

Post by hward »

i know I am just not getting it at all i have been on php.net reading and its just flying by me i usually get more from examples i get from you guys but I am not getting this stuff at all

thanks you very much
hward
Forum Contributor
Posts: 107
Joined: Mon Apr 19, 2004 6:19 pm

Post by hward »

all i get from that is the word 'Array'
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

print_r($matches)
hward
Forum Contributor
Posts: 107
Joined: Mon Apr 19, 2004 6:19 pm

Post by hward »

i was using <? echo "$matches"; ?> and getting Array

i get Array ( [0] => [UU] [=========>...........] resync [1] => [UU] ) now

whats the differents between what i was doing and print_r($matches)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

print_r is able to print the details of objects and arrays, echo is only able to print the simple variables (strings, integers, floats)
hward
Forum Contributor
Posts: 107
Joined: Mon Apr 19, 2004 6:19 pm

Post by hward »

so how do i get it down to just [UU] as what it returns
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$matches[1]
hward
Forum Contributor
Posts: 107
Joined: Mon Apr 19, 2004 6:19 pm

Post by hward »

is the word resync being in there going to affect it when the drives are in sysnc and the word resync is no longer in the file its reading?
hward
Forum Contributor
Posts: 107
Joined: Mon Apr 19, 2004 6:19 pm

Post by hward »

when the drives are in sync the file reads

Personalities : [raid1] read_ahead 1024 sectors md0 : active raid1 hde1[1] hdg1[0] 39078016 blocks [2/2] [UU] unused devices:

I am guessing since the resync is no longer in the file thats why is won't return anything now
hward
Forum Contributor
Posts: 107
Joined: Mon Apr 19, 2004 6:19 pm

Post by hward »

anything wrong with doing it like this

seems to be working but I can't be sure till the drive are in sync again

Code: Select all

<?php
$str = file_get_contents("/proc/mdstat");	  
	 preg_match('#(\[[^]]+?])\s*\[[^]]+?]\s*#is',$str,$matches);
	  $raid = substr($matches[0],5)
?>
<html>
<body>
<? echo "$raid"; ?>
</body>
</html>
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

&#1111;raid1] read_ahead 1024 sectors md0 : active raid1 hde1&#1111;1] hdg1&#1111;0] 39078016 blocks &#1111;2/2] &#1111;UU] unused devices:
if that is returned when it's done syncing... this

Code: Select all

preg_match('#(\[[^]]+?])\s*\[[^]]+?]\s*#is',$str,$matches);
will find "[2/2]".

btw, $raid = substr($matches[0],5) can be simplified to $raid = $matches[1]; for that...
Post Reply