public function testReplaceStar() { $actual = App_Util_String::replaceStar('123456789', 3, 2); $this->assertEquals($actual, '123**6789'); $actual = App_Util_String::replaceStar('123456789', 9); $this->assertEquals($actual, '123456789'); $actual = App_Util_String::replaceStar('123456789', 9, 2); $this->assertEquals($actual, '123456789'); $actual = App_Util_String::replaceStar('123456789', 9, -9); $this->assertEquals($actual, '*********'); $actual = App_Util_String::replaceStar('123456789', 9, -10); $this->assertEquals($actual, '*********'); $actual = App_Util_String::replaceStar('123456789', 9, -11); $this->assertEquals($actual, '*********'); $actual = App_Util_String::replaceStar('123456789', 3); $this->assertEquals($actual, '123******'); $actual = App_Util_String::replaceStar('123456789', 0); $this->assertEquals($actual, '*********'); $actual = App_Util_String::replaceStar('123456789', 0, 2); $this->assertEquals($actual, '**3456789'); $actual = App_Util_String::replaceStar('123456789', 3, -3); $this->assertEquals($actual, '1***56789'); $actual = App_Util_String::replaceStar('123456789', 1, -5); $this->assertEquals($actual, '**3456789'); $actual = App_Util_String::replaceStar('123456789', 3, -3); $this->assertEquals($actual, '1***56789'); $actual = App_Util_String::replaceStar('123456789', -3, 2); $this->assertEquals($actual, '123456**9'); $actual = App_Util_String::replaceStar('123456789', -3, 5); $this->assertEquals($actual, '123456***'); $actual = App_Util_String::replaceStar('123456789', -1, 2); $this->assertEquals($actual, '12345678*'); $actual = App_Util_String::replaceStar('123456789', -1, -2); $this->assertEquals($actual, '1234567**'); $actual = App_Util_String::replaceStar('123456789', -4, -7); $this->assertEquals($actual, '******789'); $actual = App_Util_String::replaceStar('123456789', -1, -3); $this->assertEquals($actual, '123456***'); $actual = App_Util_String::replaceStar('123456789', -1); $this->assertEquals($actual, '*********'); $actual = App_Util_String::replaceStar('123456789', -2); $this->assertEquals($actual, '********9'); $actual = App_Util_String::replaceStar('123456789', -9); $this->assertEquals($actual, '*23456789'); $actual = App_Util_String::replaceStar('123456789', -10); $this->assertEquals($actual, '123456789'); $actual = App_Util_String::replaceStar('123456789', -10, -2); $this->assertEquals($actual, '123456789'); }
利用PHP将部分内容用星号替换(2)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:http://www.heiqu.com/1321ee36e9189347327860983c82c4b6.html