You can use preg_split('//u', $yourText, -1, PREG_SPLIT_NO_EMPTY)
and array_map
like this:
$yourText="TEXTRANDOM";
// execute a function for every letter in your string
$arrayOfTags = array_map(function (string $letter): string {
return '1'.$letter.'_'; // concat every letter with number and _
}, preg_split('//u', $yourText, -1, PREG_SPLIT_NO_EMPTY));
echo implode('', $arrayOfTags); // make the array into a string back again
str_split
will split the string into bytes instead of letters. To split the string into array of letters you can use preg_split('//u', $yourText, -1, PREG_SPLIT_NO_EMPTY)
.
You can also do it with just a loop:
$arrayOfletters = preg_split('//u', $yourText, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrayOfletters as $letter) {
echo '1'.$letter.'_';
}
0
solved How to add every single charater end and begining