[Solved] How to get credentials from a String with many characters with substr and store them in variables


Here is a non Regex version of what you are trying to achieve.

$str = "server_name::IMACW10\COZMOSQLEXPRESS @database_name::OneTwoThreePet username::pauline_pet databasePass::root";
$test = explode(" ", $str);
$array = array();
foreach($test as $key){
    $newkey = strtok($key,":");
    $array[$newkey] = substr($key, strpos($key, ":") + 2);   
}
list($server, $dbname, $username, $pass) = array_values($array);
echo '$serverName=".$server."<br> $databaseName=".$dbname."<br> $username=".$username."<br> $pass=".$pass;

Output:

$serverName=IMACW10\COZMOSQLEXPRESS
$databaseName=OneTwoThreePet
$username=pauline_pet
$pass=root

I hope this may help you.

solved How to get credentials from a String with many characters with substr and store them in variables