extract first 5 and last 5 characters from a string using php?
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: "aabbccddeeffg开发者_运维百科ghh" will become "aabbcfgghh".
First of all - accept your recent answers.
You can do this with substr
function:
$input = 'aabbccddeeffgghh';
$output = substr($input, 0, 5) . substr($input, -5);
$extract = substr($input,0,5) . substr($input,-5);
Use substr - http://php.net/manual/en/function.substr.php
$hash = "aabbccddeeffgghh";
$tenChars = substr( $hash, 0, 5) . substr( $hash, -5 ); // "aabbcfgghh"
You want to use the substr function:
$md5hash = '098f6bcd4621d373cade4e832627b4f6';
$front_and_back = substr($md5hash,0,5) . substr($md5hash,-5);
$string = "aabbccddeeffgghh";
$string1 = substr($string,0,5);
$string2 = substr($string,-5);
$string = $string1 . $string2 ;
精彩评论