You can access characters from a string as if it were an array.
Note: as warned in the comments, accented characters (UTF-8) occupy two spaces instead of one, so to detect this type of character, we see if its code (Ord) has value >= 127.
See this table: https://www.utf8-chartable.de/unicode-utf8-table.pl?utf8=dec
This way, the code below makes this kind of conference, without using PHP functions as you requested.
<?php
$str = "àbcÂef"; // visualmente são 6 caracteres, mas internamente são 8 (2 UTF)
$i = 0; // pointer para a string
$c = 0; // contador de caracteres
while ($str[$i]<>"") {
if (ord($str[$i]) >= 127) // se for utf, despreza o caractere seguinte
$i++;
$c++;
$i++;
}
echo $c;
Will show: 6
(See the code working on https://ideone.com/Gk8JFS)
And why can’t you use strlen?
– Woss
This is good, can not use PHP functions but want to use PHP.
– user60252
can use Empty() ?
– Victor Eyer
String in which encoding? If it is not ASCII starts to get complicated.
– bfavaretto
A String with any value
– Rodolfo
Explain why you can’t use PHP functions to be clearer.
– Sam
Empty() may use
– Rodolfo
I am learning PHP and my advisor told me to try to do without specific functions, but I was not able to think of anything, but now I’m testing here, I think I should achieve
– Rodolfo
It will depend on the encoding of the tb page.
– Sam
Page encoding is just an input with a button, while in PHP I am extracting the input value and storing it in a variable
– Rodolfo
And then you got?
– Sam