Strings Flashcards
What is the difference between ‘’ y “” ?
Que en “” puedo poner la variable directo sin concatenar:
“mi nombre es $nombre”
How do you get the length of a string?
strlen($string)
How do you trim a string?
trim($string)
How do you trim the left side of a string?
ltrim($string)
How do you trim the right side of a string?
rtrim($string)
How do you count the number of words of a string?
str_word_count($string)
How do you reverse a string?
strrev($string)
How do you make the entire string into uppercase?
strtoupper($string)
How do you make the entire string into lowercase?
strtolower($string)
How do you make the first character uppercase?
ucfirst($string)
How do you make the first character lowercase?
lcfirst($string)
How do you capitalize the first char of every word?
ucwords($string)
How do you find the index of a word?
strpos($string,’word’)
How do you find the index of a word no without taking into account capitalization?
stripos($string,’word’)
How do I get a substring from a certain index?
substr($string,index)
How do I replace a word for another one in a string?
str_replace(‘word’,’php’,$string)
Ho do I replace a word for another on without taking into account capitalization?
str_replace(‘word’,’php’,$string)
How do you do a multi line text?
$string=”
hello,
this is multi
line.
“
then nl2br($string);
this will set it multiline when printing.
How do you use htmlentities and what do you useit for?
Se usa para que convierta los caracteres reservados en html entities. por ejemplo para que convierta < en <
entonces si hago htmlentities(‘<b>Hello</b>’) en el html lo va a tomar como <b>Hello</b> y en lo que muestra en el browser lo va a mostrar literalmente <b>Hello</b> sin hacer el negrita.
Si tengo un texto donde los caracteres reservados fueron convertidos a html entities, como hago para que vuelvan a ser caracteres reservados?
uso html_entity_decode(<b>Hello</b>) y eso va a hacer que se lea en negrita.