I
I
Ibishka2020-05-14 14:10:26
PHP
Ibishka, 2020-05-14 14:10:26

Which is better substr or mb_substr?

A person in one video said that I recommend always using mb_subster and with utf-8 encoding. Is the site in English is it always better to use mb_subster?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman Sarvarov, 2020-05-14
@Ibishka

If you assume that the passed string may contain letters NOT of the Latin alphabet - use mb_substr, if you are sure that a string is transferred there, where the letters will be only Latin (for example, login or password), then substr can be dispensed with.
mb_substr will not eat Cyrillic letters, but it will spend a little more resources (but not critically and imperceptibly).

F
FanatPHP, 2020-05-14
@FanatPHP

This is a very bad question.
You do not even ask what is the difference between these two functions, let alone understand what they do and draw your own conclusion based on the information received.
You are only interested in the binary answer - yes or no.
I should immediately upset you - you won’t get far on binary answers (and in general on answers to the question “how”, and not “why”). Programming is too complicated a science. If you are interested in such answers, then it is better to go to McDonald's as a waiter. There are clear answers to all questions.
If you want to continue programming, you will have to learn to learn. And draw your own conclusions. And ask "good" questions, like "I thought about it and decided that substr should be used in such cases, mb_substr - in such cases" or "I thought that it's really better to always use mb_substr, because - (... you give your argument ...). I'm right?"

I
Ilya, 2020-05-14
@rpsv

The description of the function itself has details of what it is for (it does not eat characters): https://www.php.net/manual/ru/function.mb-substr.php
Visually, it looks like this:

console
5ebd2a93093af183364313.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question