String is the most common type of variable in programming, no matter the language. Every type of referential textual uses this format to be handled or stored, so all programming languages ​​provide many resources to work with them.

In PHP, the commands for working with String are diverse, check out some following.

Character Count strlen ()

This function is used to count the number of characters in a string, as shown below:


$str1 = “”;
$str2 = “scriptcase”;
echo (“String 1: ” . strlen($str1) . ” characters .<BR>”);
echo (“String 2: ” . strlen($str2) . ” characters .<BR>”);


Uppercase strtoupper() and Lowercase strtolower()

To convert all the letters in a string to uppercase just use the reference strtoupper() to lowercase using strtolower(). Both convert all the letters, but not work as opposing case find a string of characters that is already in uppercase or lowercase.


$cd = “abc”;
$text1 = “It is a Test.”;
$cdMa = strtoupper($cd);
$texto1Me = strtolower($text1);



Since version 4.2.0 of PHP for Windows, the library CTYPE was added for use. From the verification method chosen if returns a value of true or false and that there is a greater control over the strings of the project. Check out the methods below:

  • ctype_alnum — Verifica se os caracteres são alfanuméricos;
  • ctype_alpha — Verifica se os caracteres são apenas alfabéticos;
  • ctype_cntrl — Verifica se os caracteres são de controle;
  • ctype_digit — Verifica se os caracteres são apenas numéricos;
  • ctype_graph — Verifica se os caracteres são imprimíveis. Isso deduz que sejam caracteres possuam alguma forma que se possa visualizar, portanto, espaços em branco não são considerados imprimíveis por esta função;
  • ctype_lower — Verifica se os caracteres estão minúsculos;
  • ctype_print — Verifica se os caracteres são imprimíveis. Isso exclui quebras de linhas e outros controles de fluxo de texto;
  • ctype_punct — Verifica se é um caractere imprimível que não é um espaço em branco, letra ou numéro, como por exemplo, dois-pontos (:), ponto de interrogação (?), vírgula (,), …;
  • ctype_space — Verifica se os caracteres são espaços em branco;
  • ctype_upper — Verifica se os caracteres são maiúsculos;
  • ctype_xdigit — Verifica se os caracteres representam um dígito hexadecimal. Ou seja, números e letras de A a F.


In PHP, different from most programming languages​​, there is no need to declare the type of the variable, so the controls and checks the data type must be well considered and implemented. In the case of the string, there are several ways to validate and help the programmer to have much more control over this item.

By ,

July 23, 2013


You might also like…

5 reasons you can’t miss a Black Friday Scriptcase!

This November we bring you the biggest and most important discounts of the year! And do you know wh...

Taking a look at Scriptcase version 9.7

After the big Scriptcase 9.7 presentation event, we have a new version of Scriptcase for download, ...

October Newsletter

Follow the latest news for the month of October! Webinars, blog posts, videos, and more. WEB...

You might also like…

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at Learn more about our Privacy Police.