Jump to content

[SOLVED] like explode ex.....


nathanmaxsonadil

Recommended Posts

is there something like explode but instead of like this

$data = "foo:*:1023:1000::/home/foo:/bin/sh";
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
echo $user; // foo
echo $pass; // *

it would go like this

$data = "foo:*:1023:1000::/home/foo:/bin/sh";
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
echo $user; // foo:
echo $pass; // *:

 

Link to comment
https://forums.phpfreaks.com/topic/67486-solved-like-explode-ex/
Share on other sites

You lose the colon when you perform the explode, so just manually concatenate it back on:

$data = "foo:*:1023:1000::/home/foo:/bin/sh";
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
echo $user . ":"; // foo:
echo $pass . ":"; // *:

Or simply add a different character to do the explode on.

 

<?php

$data = "foo:*:1023:1000::/home/foo:/bin/sh";
$data = str_replace(':', ':|', $data);

list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode("|", $data);

echo $user; // foo:
echo $pass; // *:

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.