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

自闭症网瘾萝莉.ら 提交于 2019-12-12 18:26:53

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!