PHP inserts a string into a random position of a string

Source: Internet
Author: User

/**
* Randomly inserts a string into a string
* @param unknown_type $oldstr old string
* @param unknown_type $instr the inserted string
* @param unknown_type $encoding string encoding
*/
function Rand_in_str ($oldstr, $instr, $encoding) {
$len = Mb_strlen ($oldstr, $encoding);
$insert _point = Mt_rand (1, $len-1);
$pre _str = mb_substr ($oldstr, 0, $insert _point, $encoding);
$after _str = Mb_substr ($oldstr, $insert _point, $len-$insert _point, $encoding);
$newstr = $pre _str. $instr. $after _str;
return $newstr;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.