Strings Flashcards

1
Q

What is the difference between ‘’ y “” ?

A

Que en “” puedo poner la variable directo sin concatenar:

“mi nombre es $nombre”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you get the length of a string?

A

strlen($string)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you trim a string?

A

trim($string)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you trim the left side of a string?

A

ltrim($string)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you trim the right side of a string?

A

rtrim($string)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you count the number of words of a string?

A

str_word_count($string)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you reverse a string?

A

strrev($string)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you make the entire string into uppercase?

A

strtoupper($string)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you make the entire string into lowercase?

A

strtolower($string)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you make the first character uppercase?

A

ucfirst($string)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you make the first character lowercase?

A

lcfirst($string)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you capitalize the first char of every word?

A

ucwords($string)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you find the index of a word?

A

strpos($string,’word’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you find the index of a word no without taking into account capitalization?

A

stripos($string,’word’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do I get a substring from a certain index?

A

substr($string,index)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do I replace a word for another one in a string?

A

str_replace(‘word’,’php’,$string)

17
Q

Ho do I replace a word for another on without taking into account capitalization?

A

str_replace(‘word’,’php’,$string)

18
Q

How do you do a multi line text?

A

$string=”
hello,
this is multi
line.

then nl2br($string);

this will set it multiline when printing.

19
Q

How do you use htmlentities and what do you useit for?

A

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.

20
Q

Si tengo un texto donde los caracteres reservados fueron convertidos a html entities, como hago para que vuelvan a ser caracteres reservados?

A

uso html_entity_decode(<b>Hello</b>) y eso va a hacer que se lea en negrita.