Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
I want to replace the first 3 characters and last 3 characters with *
sign without using any built in functions.
$string = array("johndoee","shawnmarsh","peterparker","johndoee","shawnmarsh","peterparker");
Can you guide me? Is there any way to do this?
This seems fairly pointless, but it's possible using string access and modification by character.
foreach ($strings as &$string) {
for ($i=0; $i < 3; $i++) {
$string[$i] = '*';
$string[-($i+1)] = '*';
}
}
Note that this won't work properly if the string contains multibyte characters, because it's accessing the string as a byte array.
Also note that this requires PHP 7.1 in order to use the negative indexes. If you don't have PHP 7.1 I don't know of a way to replace the last three characters without using any functions.