RE: [PHP] How to strip extra characters off of a string
| From: | Timothy Hitchens \(HiTCHO\) | Date: | Thu, 09 Jan 2003 02:20:35 +0000 |
| Subject: | RE: [PHP] How to strip extra characters off of a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-130847@lists.php.net to get a copy of this message | ||
Give this a shot ... a bit of a hack but works for you:
<?php
$string = '
Disk quotas for group site53 (gid 165):
Filesystem blocks quota limit grace files quota limit
grace
/dev/hda4 57070 307201 307200 1146 0 0
';
$test = strstr($string, 'hda');
// replace two spaces with one - ensure differences in quota function
doesn't effect
$test = eregi_replace(' ', ' ', $test);
// split on spaces
$test = explode(' ', $test);
echo trim($test[2]);
?>
Timothy Hitchens (HiTCHO)
Open Platform Consulting
e-mail: tim@hitcho.com.au
> -----Original Message-----
> From: rdkurth@starband.net [mailto:rdkurth@starband.net]
> Sent: Thursday, 9 January 2003 12:17 PM
> To: php-general
> Subject: [PHP] How to strip extra characters off of a string
>
>
>
> I need to be able to just extract the number that is right
> Under blocks in this example it is the number 57070. This was
> generated by the quota -g groupname command.
>
> Disk quotas for group site53 (gid 165):
> Filesystem blocks quota limit grace files
> quota limit grace
> /dev/hda4 57070 307201 307200 1146
> 0 0
>
> I have tried using some of the string
> functions like I used
> $test=strstr ($test, "hda");
> $test= substr("$test",7);
> This well get me up to the start of the number but now I need
> to get read of every thing after the number. Is there a
> better way of getting this info or for striping all the other
> stuff away.
>
>
>
>
> --
> Best regards,
> rdkurth mailto:rdkurth@starband.net
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>