How to make the first 4 characters of a string smaller than the others

Asked

Viewed 991 times

0

I did a search and couldn’t find a code to leave only the first 4 characters of a string with a smaller size.

I tried this code:

$str = "Códigos"; 
$str = strtolower($str);

Only that I need to leave are the first 4 numbers smaller than the others. What I always find refer to strings.

2 answers

5


I think you can handle it this way:

$numero = '1234567890';
echo '<small>'.substr($numero, 0, 4).'</small>'.substr($numero, 5);

Using substr I separated the string into 2 parts, one with the first 4 numbers .substr(0, 4) and one with the rest .substr(5) and added the tag <small> to show in a smaller font.

The result will be something like this in the browser:

<small>1234</small>567890
  • 2

    Oxe, a negative less than 8 seconds.

  • I gave you -1 because despite being an attempt to help, you didn’t take into consideration that AP might not understand what language this is. And the question tag is PHP.

  • I gave -1 because not only is the answer not in accordance with the question, the question is still weak, immature and should not be rewarded.

  • Poxa @Diegofelipe , is not pq do not know the exact address I can not point the right direction. I made it clear in the answer that I do not know PHP, but the way is that same.

  • @Marcoauréliodeleu, ok, you don’t need to make me positive/reward. But you didn’t need to make me negative, because that’s the way.

  • Don’t get me wrong, but if I have a question in java and you give me an example in C# pq are similar, it’s not the same thing as showing a direction. Add a small explanation of what the code does, because in addition to showing in another language, you haven’t even explained how the code works. The intention of -1 is to make the response better only, not an attempt to retaliate.

  • @Diegofelipe, justo. I edited the answer. Really I could deliver a better answer.

  • @Marcoauréliodeleu, I edited the answer. Can validate, please?

  • 1

    @Danielomine, I edited the answer and your edition is gone. But thanks for the contribution with PHP.

  • 1

    @Thiagolunardi, as I said, the question is not only the lack of quality in your answer, but also the lack of quality of the question. I don’t think questions like that should be encouraged. I commented to the author about the flaws of the questions and so far it has not published trial code, errors, nothing. Suggested reading: http://meta.stackoverflow.com/a/308358/1014588

Show 5 more comments

2

In php you can make a substr() to take the first 4 positions and then use the <font> to make it smaller .

Example:

$str = "Gabriel Rodrigues";

function examplo($str) {
   return "<font size='1'>" . substr($str, 0, 4) . "</font>" . substr($str, 5);
}

echo examplo($str);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.