A
A
Alexey Tolstoukhov2018-04-03 12:05:21
PHP
Alexey Tolstoukhov, 2018-04-03 12:05:21

How to remove extra text from a line?

There is a line:

$SHA$7b11fd7c3568e2cf$2e0380db347bbc210bb10c117dbcb7a7fdba831513eec387666571c7a3ca051e

Divided into hash and salt.
$salt = 7b11fd7c3568e2cf

$hash = 2e0380db347bbc210bb10c117dbcb7a7fdba831513eec387666571c7a3ca051e

And remove the rest. How to convert this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stimulate, 2018-04-03
@leha2002828

$var = '$SHA$7b11fd7c3568e2cf$2e0380db347bbc210bb10c117dbcb7a7fdba831513eec387666571c7a3ca051e';
$var = str_replace('$SHA$', '', $var);
$var_a = explode('$', $var);
$salt = $var_a[0];
$hash = $var_a[1];

echo $salt.'<br/>'.$hash;

A
Alexander, 2018-04-03
@zkelo

$regexp = '/^\$SHA\$([a-f0-9]+)\$([a-f0-9]+)$/';
$hash = '$SHA$7b11fd7c3568e2cf$2e0380db347bbc210bb10c117dbcb7a7fdba831513eec387666571c7a3ca051e';
$matches = [];
preg_match($regexp, $hash, $matches);

echo 'Хэш: ', $matches[2], '. Соль: ', $matches[1], '.';

Regex101 .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question