开发者

extract first 5 and last 5 characters from a string using php?

开发者 https://www.devze.com 2023-03-28 14:43 出处:网络
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?

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 ;

0

精彩评论

暂无评论...
验证码 换一张
取 消