You are here: Re: [PHP] php equivalent for cut « PHP « IT news, forums, messages
Re: [PHP] php equivalent for cut

Posted by tg-php on 09/06/05 19:18

The closest you get to 'cut' in PHP is probably the 'explode' command. It splits a string by a delimiter like 'cut' does, only it dumps the results into an array:

$etcpasswd = "username:passwd:123:345::/home/username:/bin/sh";

$pwdarr = explode(":", $etcpasswd);

echo $pwdarr[4];

That should give you the 5th 'column' of the $etcpasswd string.

OR.. you could do this:

list($username, $passwd, $userid, $groupid, $something, $homedir, $defshell) = explode(":", $etcpasswd);

That'll take the array returned from explode() and put it into the variables used in $list. It's been ages since I've messed with *nix /etc/passwd files, so forgive any inaccuracies in the field names I've used above. You get the idea though.

Good luck Michelle!

-TG

= = = Original message = = =

Hello,

I am searching for the right equivalent for "cut -d : -f5"
but it must work with php4.

Since the website <http://www.php.net/manual/de/> has no
seperated manuals for php4 and php5, it is not easy to
find the right stuff.

Greetings and good evening
Michelle


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация