问题
I have an MD5 alpha-numeric. How can I get the first five characters and last five characters, and put them in one string using PHP
?
For example: "aabbccddeeffgghh" will become "aabbcfgghh".
回答1:
First of all - accept your recent answers.
You can do this with substr function:
$input = 'aabbccddeeffgghh';
$output = substr($input, 0, 5) . substr($input, -5);
回答2:
$extract = substr($input,0,5) . substr($input,-5);
回答3:
Use substr - http://php.net/manual/en/function.substr.php
回答4:
$hash = "aabbccddeeffgghh";
$tenChars = substr( $hash, 0, 5) . substr( $hash, -5 ); // "aabbcfgghh"
回答5:
You want to use the substr function:
$md5hash = '098f6bcd4621d373cade4e832627b4f6';
$front_and_back = substr($md5hash,0,5) . substr($md5hash,-5);
回答6:
$string = "aabbccddeeffgghh";
$string1 = substr($string,0,5);
$string2 = substr($string,-5);
$string = $string1 . $string2 ;
来源:https://stackoverflow.com/questions/7075941/extract-first-5-and-last-5-characters-from-a-string-using-php