Completed
Push — 4.1 ( c2b28b...e69caa )
by Andrea
13:26
created

TabellaXls::getValueCell()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5.3197

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 25
ccs 8
cts 22
cp 0.3636
rs 9.568
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 5.3197
1
<?php
2
3
namespace Fi\CoreBundle\Utils\Export;
4
5
use PhpOffice\PhpSpreadsheet\Spreadsheet;
6
use PhpOffice\PhpSpreadsheet\Writer\Xls;
7
use PhpOffice\PhpSpreadsheet\Style\Fill;
8
use PhpOffice\PhpSpreadsheet\Style\Border;
9
use Fi\CoreBundle\Utils\Entity\DoctrineFieldReader;
10
11
class TabellaXls
12
{
13
14 1
    public function esportaexcel($parametri = array())
15
    {
16 1
        set_time_limit(960);
17 1
        ini_set('memory_limit', '2048M');
18
19
        //Creare un nuovo file
20 1
        $spreadsheet = new Spreadsheet();
21 1
        $objPHPExcel = new Xls($spreadsheet);
22 1
        $spreadsheet->setActiveSheetIndex(0);
23
24
        // Set properties
25 1
        $spreadsheet->getProperties()->setCreator('Comune di Firenze');
26 1
        $spreadsheet->getProperties()->setLastModifiedBy('Comune di Firenze');
27
28
29 1
        $header = $parametri['parametritabella'];
30 1
        $rows = $parametri['recordstabella'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
31
        //Scrittura su file
32 1
        $sheet = $spreadsheet->getActiveSheet();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
33 1
        $titolosheet = 'Esportazione ' . $parametri['nomecontroller'];
34 1
        $sheet->setTitle(substr($titolosheet, 0, 30));
35 1
        $sheet->getParent()->getDefaultStyle()->getFont()->setName('Verdana');
36
37 1
        $this->printHeaderXls($header, $sheet);
38
39 1
        $this->printBodyXls($header, $rows, $sheet);
40
41
        //Si crea un oggetto
42 1
        $todaydate = date('d-m-y');
43
44 1
        $filename = 'Exportazione';
45 1
        $filename = $filename . '-' . $todaydate . '-' . strtoupper(md5(uniqid(rand(), true)));
46 1
        $filename = $filename . '.xls';
47 1
        $filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename;
48
49 1
        if (file_exists($filename)) {
50
            unlink($filename);
51
        }
52
53 1
        $objPHPExcel->save($filename);
54
55 1
        return $filename;
56
    }
57 1
    private function printHeaderXls($testata, $sheet)
58
    {
59 1
        $indicecolonnaheader = 1;
60 1
        $letteracolonna = 0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
61 1
        foreach ($testata as $modellocolonna) {
62 1
            if ($modellocolonna["escluso"] === false) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal escluso does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
63
                //Si imposta la larghezza delle colonne
64 1
                $letteracolonna = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($indicecolonnaheader);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
65 1
                $width = (int) $modellocolonna['larghezza'] / 7;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 20 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
66 1
                $indicecolonnaheadertitle = $modellocolonna['etichetta'];
67 1
                $coltitle = strtoupper($indicecolonnaheadertitle);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 17 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
68 1
                $sheet->setCellValueByColumnAndRow($indicecolonnaheader, 1, $coltitle);
69 1
                $sheet->getColumnDimension($letteracolonna)->setWidth($width);
70
71 1
                ++$indicecolonnaheader;
72
            }
73
        }
74
75 1
        if ($indicecolonnaheader > 0) {
76
            //Si imposta il colore dello sfondo delle celle
77
            //Colore header
78
            $style_header = array(
79 1
                'fill' => array(
80 1
                    'type' => Fill::FILL_SOLID,
81
                    'color' => array('rgb' => 'E5E4E2')
82
                ),
83
                'font' => array(
84
                    'bold' => true
85
                )
86
            );
87 1
            $sheet->getStyle('A1:' . $letteracolonna . '1')->applyFromArray($style_header);
88
        }
89
90 1
        $sheet->getRowDimension('1')->setRowHeight(20);
91 1
    }
92 1
    private function printBodyXls($header, $rows, $sheet)
93
    {
94 1
        $row = 2;
95 1
        foreach ($rows as $riga) {
96 1
            $col = 1;
97 1
            foreach ($header as $colonnatestata => $valorecolonnatestata) {
98 1
                if ($valorecolonnatestata["escluso"] === false) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal escluso does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
99 1
                    $dfr = new DoctrineFieldReader($riga);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
100 1
                    $oggetto = $dfr->getField2Object($colonnatestata, $riga);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
101 1
                    $valorecampo = $dfr->object2view($oggetto, $valorecolonnatestata["tipocampo"]);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal tipocampo does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
102 1
                    if ($valorecampo === '' || $valorecampo === null) {
103 1
                        $col = $col + 1;
0 ignored issues
show
Coding Style introduced by
Increment operators should be used where possible; found "$col = $col + 1;" but expected "$col++"
Loading history...
104 1
                        continue;
105
                    }
106 1
                    $sheet->setCellValueByColumnAndRow($col, $row, $this->getValueCell($valorecolonnatestata["tipocampo"], $valorecampo));
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal tipocampo does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
107 1
                    $this->setCellFormat($sheet, $col, $row, $valorecolonnatestata["tipocampo"]);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal tipocampo does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
108 1
                    $col = $col + 1;
0 ignored issues
show
Coding Style introduced by
Increment operators should be used where possible; found "$col = $col + 1;" but expected "$col++"
Loading history...
109
                }
110
            }
111 1
            $sheet->getRowDimension($row)->setRowHeight(18);
112 1
            ++$row;
113
        }
114 1
    }
115 1
    private function getValueCell($tipocampo, $valorecella)
116
    {
117 1
        $valore = null;
118 1
        switch ($tipocampo) {
119 1
            case 'date':
120
                $d = (int) substr($valorecella, 0, 2);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
121
                $m = (int) substr($valorecella, 3, 2);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
122
                $y = (int) substr($valorecella, 6, 4);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
123
                $t_date = \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel($y, $m, $d);
124
                $valore = $t_date;
125
                break;
126 1
            case 'datetime':
127
                $d = (int) substr($valorecella, 0, 2);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
128
                $m = (int) substr($valorecella, 3, 2);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
129
                $y = (int) substr($valorecella, 6, 4);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
130
                $h = (int) substr($valorecella, 11, 2);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
131
                $i = (int) substr($valorecella, 14, 2);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
132
                $t_date = \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel($y, $m, $d, $h, $i, 0);
133
                $valore = $t_date;
134
                break;
135
            default:
136 1
                $valore = $valorecella;
137 1
                break;
138
        }
139 1
        return $valore;
140
    }
141 1
    private function setCellFormat($sheet, $indicecolonna, $row, $tipocampo)
142
    {
143 1
        $letteracolonna = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($indicecolonna);
144 1
        switch ($tipocampo) {
145 1
            case 'text':
146
                $sheet->getStyle($letteracolonna . '2:' . $letteracolonna . $row)
147
                        ->getNumberFormat()
148
                        ->setFormatCode("@");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal @ does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
149
                break;
150 1
            case 'string':
151 1
                $sheet->getStyle($letteracolonna . '2:' . $letteracolonna . $row)
152 1
                        ->getNumberFormat()
153 1
                        ->setFormatCode("@");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal @ does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
154 1
                break;
155 1
            case 'integer':
156 1
                $sheet->getStyle($letteracolonna . '2:' . $letteracolonna . $row)
157 1
                        ->getNumberFormat()
158 1
                        ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER);
159 1
                break;
160 1
            case 'float':
161
                $sheet->getStyle($letteracolonna . '2:' . $letteracolonna . $row)
162
                        ->getNumberFormat()
163
                        ->setFormatCode('#,##0.00');
164
                break;
165 1
            case 'decimal':
166
                $sheet->getStyle($letteracolonna . '2:' . $letteracolonna . $row)
167
                        ->getNumberFormat()
168
                        ->setFormatCode('#,##0.00');
169
                break;
170 1
            case 'number':
171
                $sheet->getStyle($letteracolonna . '2:' . $letteracolonna . $row)
172
                        ->getNumberFormat()
173
                        ->setFormatCode('#,##0.00');
174
                break;
175 1
            case 'datetime':
176
                //\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DDMMYYYYSLASH
177
                $sheet->getStyle($letteracolonna . '2:' . $letteracolonna . $row)
178
                        ->getNumberFormat()
179
                        ->setFormatCode("dd/mm/yyyy hh:mm:ss");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal dd/mm/yyyy hh:mm:ss does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
180
                break;
181 1
            case 'date':
182
                $sheet->getStyle($letteracolonna . '2:' . $letteracolonna . $row)
183
                        ->getNumberFormat()
184
                        ->setFormatCode("dd/mm/yyyy");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal dd/mm/yyyy does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
185
                break;
186
            default:
187 1
                $sheet->getStyle($letteracolonna . '2:' . $letteracolonna . $row)
188 1
                        ->getNumberFormat()
189 1
                        ->setFormatCode("@");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal @ does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
190 1
                break;
191
        }
192 1
    }
193
}
194