M
M
Michael R.2015-10-01 15:27:49
PHP
Michael R., 2015-10-01 15:27:49

How to correctly count the number of characters here?

Hello! There was a task, to count up in a piece of the text how many characters there. I found the required variable, tested it at the test site, everything works as it should!

$str = 101;
$strTotal = strlen($str);
echo "$strTotal";
3

But in practice, it turned out that the piece of text I needed had some kind of "strange variable", perhaps this is a js variable? The variable itself: %file_description%
I tried by analogy with what I got at the polygon and in the end everything died out:
$strTotal = strlen(%file_description%);
echo "$strTotal";

How in this case to count the number of characters that are output in %file_description%?
Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Zhukov, 2015-10-02
@Adobe

There may be problems with counting Cyrillic characters, use mb_strlen()

L
lyeskin, 2015-10-01
@lyeskin

How bad is your knowledge... %file_description% is not a php variable and not a variable at all, and you can't use it in php functions.

I
Ivanq, 2015-10-01
@Ivanq

%file_description%- not a variable. All php variables start with $. Most likely, this variable must first be replaced with some value.

$file_description = "Hello World";
$str = "abc %file_description% def";
$str = str_ireplace("%file_description%", $file_description, $str); // Заменяет %file_description% на значение переменной $file_description
$strTotal = strlen($str);
echo "$strTotal";
// abc(3) + def(3) + " "(1) + " "(1) + Hello(5) + World(5) + " "(1) = 19

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question