|
In this chapter they will comment on all the particulars related to chains of characters, the existing functions, etc.
Chains of characters
A chain consists of a sequence of characters that are understood between a few delimitadores that they can be:
- simple quotation marks ''
- double quotes ""
- inlaid document <<<>
In case it is wished for example some "" inside the quotation marks of the chain of character it is necessary to realize the action that names to escape a character that consists of preceding it of one that is to say ". The special characters that can appear inside a document with delimitation are:
| Sequence |
Meaning |
| n |
New line |
| r |
Car comeback |
| t |
Horizontal tabulation |
|
Inverted bar |
| $ |
Sign of dollar |
| " |
Double quotes |
| [0-7] {1,3} |
Character ASCII that coincides with the number octal |
| x [0-9A-Fa-f] {1,2} |
Character ASCII that coincides with the number hexadecimal |
The case of inlaid document is different from that of both quotation marks. His syntax is the following one:
<<<Identifier
Chain of characters
Identifier;
The result obtained with inlaid document is the showed text just as it has interfered.
The function chr (value) is returned us in a variable of the type chain by the character of the table of codes ASCII associated with a value that receives like parameter, the value that passes must be between 0 and 255.
The function ord (chain) returns us an entire number that corresponds to the code ASCII of the first character that receives like parameter.
Chains visualization
- I begin: It is the most used visualization way. His syntax is the following one: I throw "text";
- Print: It is the simplest of all and she is in charge of showing a chain of characters on his standard exit. He does not support any exit format and his syntax is: print (chain);
- Printf (format, [values]); His functioning is the same than in the previous case. The only difference is that this one supports formats of exit as his alignment (for defect to the left), numerical value (minimal number of characters that must appear), I number of decimal and type of information which possibilities are:
| Symbol |
Meaning |
| % |
It represents the symbol of the percentage |
| b |
The argument talks each other how nº point and it is represented in binary codification. |
| c |
The argument talks each other how nº point and there appears the character which code ASCII corresponds to the value. |
| d |
The argument talks each other how nº point and it is represented in decimal codification without fractional part |
| f |
The argument talks each other like a type nº double and is represented like a decimal one without floating comma |
| or |
The argument talks each other like an entire nº and is represented in codification octal |
| s |
The argument talks each other and represents like a chain of characters |
| x |
The argument is considered to be an entire nº and is represented in codification hexadecimal in small letters |
| X |
The argument is considered to be an entire nº and is represented in codification hexadecimal in capital letters |
- Sprintf (format, [values]); his functioning is identical to printf. The only thing that the chain resultant of applying a certain format to him keeps in a variable.
Alteration of the content
Sometimes it is necessary to use the above mentioned functions to alter the format of exit of the chains. The functions used to modify the above mentioned format are:
- chop (chain); He returns the chain of characters with the eliminated characters of target and new line
- ltrim (chain); It eliminates the targets that appear to the right of a chain of characters
- rtrim (chain); It eliminates the targets that appear by the right in a chain of characters
- trim (chain); It eliminates the targets that appear to left and right of the chain of characters
- str_pad (chain, length, filling, place); He verifies if the length is minor than the stated value, if it is like that adds the necessary characters. The place of adding can be:
str_pad_left it adds for the right (silence option), str_pad_right it adds for the left and str_pad_both it adds for both ends.
- str_repeat (character, numero_veces); the stated number of times Repeats a character
- strtolower (chain); the whole chain Goes on to small letters
- strtoupper (chain); the whole chain Goes on to capital letters
- ucfirst (chain); the first character of a chain Goes on to capital letter
- ucwords (chain); It puts in capital letters the first character of every word of the chain
- str_replace (subcadena1, subcadena2, chain); It replaces a word with other one inside a chain
- strtr (chain, originals, translated); He translates certain characters.Ejemplo: $persona=strt ($persona, "áéíóú", "to, and, i, o, u"); thus it would change all the vowels with accent into vowels without accent.
- substr_replace (chain, piece of news, beginning, length); It replaces a portion of the content of a chain
I access to the content
- strlen (chain); There indicates the nº of characters of a chain
- count_chars (chain, way); I number of repetitions of a character in a chain. The possible ways are:
0-> Counterfoil index-linked often of appearance of all the characters of the code ASCII
1-> Counterfoil with characters ASCII often major than 0
2-> Counterfoil with characters that do not appear in the chain
3-> Chain with characters used in the code ASCII
4-> Chain with characters not used in the code ASCII
- substr_count (chain, subchain); Frequency of appearance of a chain
- strchr (chain, character); He returns the subchain that begins in the first appearance of the stated character
- strstr (chain, subchain); It locates subchain inside the original chain
- stristr (chain, subchain); Just as the previous function but without distinction between capital letters and small letters
- strpos (chain, subchain); the First occurrence of a chain in other one
- strrpos (chain, subchain); Last occurrence of a chain in other one
- ord (chain); He returns the value ASCII of a character
- substr (chain, beginning, length); Portion of text that starts in a position and has a length
- strcmp (cadena1, cadena2); He compares two chains being sensitive to capital letters and small letters
- strcasecmp (cadena1, cadena2); He compares two chains without being sensitive to capital letters and small letters
- strncmp (cadena1, cadena2, size); He compares the first N characters of a chain
- strnatcmp (cadena1, cadena2); Sensitive to capital letters and small letters. He compares two chains.
- strnatcasecmp (cadena1, cadena2); not sensitive to capital letters and small letters. He compares two chains.
- chunk_split (chain, length, divider); It takes a chain of characters and introduces dividers at a certain distance. It does not modify the original but it is a new function.
- explode (divider, chain, limit); It allows to obtain a counterfoil of chains of characters extracted from the original.
- implode (divider, elements); It joins in a chain the elements of a counterfoil using like linking the divider spent for parameter.
- parse_str (chain); It allows to extract and create variables that are part of a chain that corresponds to one "query string" received of an URL.
*Apoyo to HTML
- addcslashes (chain, list); He returns a chain that has all the escaped characters as parameter.
- addslashes (chain); He returns a chain that has all the logical escaped characters
- stripcslashes (); and stripslashes (); They receive chains that can contain characters of of leakages and the desescapan
- quotemeta (chain); Esacapa the special characters
- htmlspecialchars (chain); It carries out conversions like &->&, "->"
- htmlentities (); It converts all the characters to entities html. á happens to be á
- get_html_translation_table (htmlentities or html_specialchars); It obtains the relation of translation of every special character.
- array_flip (); He exchanges the keys for the values in array associatively.
- get_meta_tags (nombre_fichero, include_path); He returns all put them tags that a HTML contains.
- strip_tags (chain, mostrar_tags); It omits tags PHP and HTML, that thing about mostrar_tags are the chains HTML and PHP must not be omitted in the reading.
- n12br (chain); It allows to replace line jumps for <br>
- parse_url (cadena_url); He returns an associative counterfoil with the following fields:
| Field |
Meaning |
| scheme |
Http |
| host |
Ip or DNS |
| port |
port |
| user |
user name |
| password |
password |
| path |
path I complete to the resource |
| query |
query string with information to the resource |
| urldecode |
it decodes the information |
| urlencode |
It codifies the information |
|