Strings Flashcards

1
Q

Returns a string with backslashes in front of the specified characters

A
addcslashes(string,characters)
---------------
EXAMPLE:
$str = addcslashes("Hello World!","W");
echo($str); 

OUTPUT:
Hello \World!

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

Returns a string with backslashes in front of predefined characters

A
addslashes(string)
---------------
EXAMPLE:
$str = addslashes('What does "yolo" mean?');
echo($str); 

OUTPUT:
What does "yolo" mean?

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

Converts a string of ASCII characters to hexadecimal values

A
bin2hex(string)
---------------
EXAMPLE:
$str = bin2hex("Hello World!");
echo($str);

OUTPUT:
48656c6c6f20576f726c6421

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

Removes whitespace or other characters from the right end of a string

A
chop(string,charlist)
---------------
EXAMPLE:
$str = "Hello World!";
echo $str . "<br>";
echo chop($str,"World!");

OUTPUT:
Hello World!
Hello

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

Returns a character from a specified ASCII value

A
chr(ascii)
---------------
EXAMPLE:
echo chr(52) . "<br>"; // Decimal value
echo chr(052) . "<br>"; // Octal value
echo chr(0x52) . "<br>"; // Hex value

OUTPUT:
4
*
R

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

Splits a string into a series of smaller parts

A
chunk_split(string,length,end)
---------------
EXAMPLE:
$str = "Hello world!";
echo chunk_split($str,1,".");

OUTPUT:
H.e.l.l.o. .w.o.r.l.d.!.

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

Decodes a uuencoded string

A
convert_uudecode(string)
---------------
EXAMPLE:
$str = ",2&amp;5L;&amp;\@=V]R;&amp;0A `";
echo convert_uudecode($str);

OUTPUT:
Hello world!

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

Encodes a string using the uuencode algorithm

A
convert_uuencode(string)
---------------
EXAMPLE:
$str = "Hello world!";
echo convert_uuencode($str);

OUTPUT:
,2&5L;&\@=V]R;&0A `

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

Returns information about characters used in a string

A
count_chars(string,mode)
---------------
EXAMPLE:
$str = "Hello World!";
echo count_chars($str,3);

OUTPUT:
The parameter “mode 3” will return a string with all the different characters used. In this example, the characters used in “Hello World!” are:

!HWdelor

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

Outputs one or more strings

A

EXAMPLE:
echo “Hello world!”;

OUTPUT:
Hello world!

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

Breaks a string into an array

A

EXAMPLE:
$str = ‘one,two,three,four’;

// zero limit
print_r(explode(',',$str,0));
print "<br>";
// positive limit
print_r(explode(',',$str,2));
print "<br>";
// negative limit 
print_r(explode(',',$str,-1));

OUTPUT:
Array ( [0] => one,two,three,four )
Array ( [0] => one [1] => two,three,four )
Array ( [0] => one [1] => two [2] => three )

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

Writes a formatted string to a specified output stream

A
fprintf(stream,format,arg1,arg2,arg++)
---------------
EXAMPLE:
$number = 9;
$str = "Beijing";
$file = fopen("test.txt","w");
echo fprintf($file,"There are %u million bicycles in %s.",$number,$str);

OUTPUT:
40

The following text will be written to the file “test.txt”:
There are 9 million bicycles in Beijing.

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

Converts a string of hexadecimal values to ASCII characters

A

EXAMPLE:
echo hex2bin(“48656c6c6f20576f726c6421”);

OUTPUT:
Hello World!

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

Converts HTML entities to characters

A
html_entity_decode(string,flags,character-set)
---------------
EXAMPLE:
Jane &amp; 'Tarzan'<br>
Jane &amp; 'Tarzan'<br>
Jane &amp; 'Tarzan'

OUTPUT:
Jane & ‘Tarzan’
Jane & ‘Tarzan’
Jane & ‘Tarzan’

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

Converts characters to HTML entities

A

EXAMPLE:
$str = “Jane & ‘Tarzan’”;
echo htmlentities($str, ENT_COMPAT); // Will only convert double quotes
echo “<br></br>”;
echo htmlentities($str, ENT_QUOTES); // Converts double and single quotes
echo “<br></br>”;
echo htmlentities($str, ENT_NOQUOTES); // Does not convert any quotes

OUTPUT:
Jane & ‘Tarzan’
Jane & ‘Tarzan’
Jane & ‘Tarzan’

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

Converts some predefined HTML entities to characters

A
htmlspecialchars_decode(string,flags)
---------------
EXAMPLE:
$str = "This is some <b>bold</b> text.";
echo htmlspecialchars_decode($str);

OUTPUT:
This is some bold text.

17
Q

Converts some predefined characters to HTML entities

A

htmlspecialchars(string,flags,character-set,double_encode)

The predefined characters are:

&amp; (ampersand) becomes &amp;
" (double quote) becomes "
' (single quote) becomes '
 (greater than) becomes >
---------------
EXAMPLE:
$str = "This is some <b>bold</b> text.";
echo htmlspecialchars($str);

OUTPUT:
This is some <b>bold</b> text.

18
Q

Returns a string from the elements of an array

A
implode(separator,array)
---------------
EXAMPLE:
$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr);

OUTPUT:
Hello World! Beautiful Day!

19
Q

Alias of implode()

A
join(separator,array)
---------------
EXAMPLE:
$arr = array('Hello','World!','Beautiful','Day!');
echo join(" ",$arr);

OUTPUT:
Hello World! Beautiful Day!

20
Q

Converts the first character of a string to lowercase

A

EXAMPLE:
echo lcfirst(“Hello world!”);

OUTPUT:
hello world!

21
Q

Returns locale numeric and monetary formatting information

A
localeconv()
--------------
EXAMPLE:
setlocale(LC_ALL,"US");
$locale_info = localeconv();
print_r($locale_info);

OUTPUT:
Array ( [decimal_point] => . [thousands_sep] => , [int_curr_symbol] => USD [currency_symbol] => $ [mon_decimal_point] => . [mon_thousands_sep] => , [positive_sign] => [negative_sign] => - [int_frac_digits] => 2 [frac_digits] => 2 [p_cs_precedes] => 1 [p_sep_by_space] => 0 [n_cs_precedes] => 1 [n_sep_by_space] => 0 [p_sign_posn] => 3 [n_sign_posn] => 0 [grouping] => Array ( [0] => 3 ) [mon_grouping] => Array ( [0] => 3 ) )

22
Q

Removes whitespace or other characters from the left side of a string

A
ltrim(string,charlist)
--------------
EXAMPLE:
$str = "Hello World!";
echo $str . "<br>";
echo ltrim($str,"Hello");

OUTPUT:
Hello World!
World!

23
Q

Returns a string formatted as a currency string

A
money_format(string,number)
--------------
EXAMPLE:
$number = 1234.56;
setlocale(LC_MONETARY,"en_US");
echo money_format("The price is %i", $number);

OUTPUT:
The price is USD 1,234.56

24
Q

Inserts HTML line breaks in front of each newline in a string

A

EXAMPLE:
echo nl2br(“One line.\nAnother line.”);

OUTPUT:
One line.
Another line.

25
Q

Formats a number with grouped thousands

A
number_format(number,decimals,decimalpoint,separator)
---------------
EXAMPLE:
echo number_format("1000000")."<br>";
echo number_format("1000000",2)."<br>";
echo number_format("1000000",2,",",".");

OUTPUT:
1,000,000
1,000,000.00
1.000.000,00