This question already has an answer here:
i am new to PHP and i have got an issue with dynamically loaded HTML-content. I've designed a price label, which i want to be stored in one PHP-file, to make changes apply to every position on the website:
<?php
$preisschild_a = "<div class="centered"><h3>Komplett ab</h3></div><div class="preisschild redbg"><div class="preis">";
$preis_neo = "1.000,- €";
$preis_vision55 = "1.000,- €";
$preis_vision80 = "1.000,- €";
$preis_pult = "3.699,- €";
$preis_ultra = "1.000,- €";
$preis_beamcase = "1.000,- €";
$preisschild_b = "</div><div class="preis-subline">zzgl. MWST</div></div><div class="centered"><h3>Infos und Bestellung:</h3><span class="rot block"><h3>05252/9778511</h3></span></div><hr>";
?>
As you can see, i've cut the whole code into 3 pieces, to assemble it on the website again:
<?php echo "$preisschild_a"; ?>
<?php echo "$preis_pult"; ?>
<?php echo "$preisschild_b"; ?>
The fact is, that the whole page keeps beeing white. It does not work anyway.
Where's the bug? Thanx in advance!
</div>
You can't have a "
character in a string starting with "
unless you escape it (\"
).
Re-write them so they look like this:
$preisschild_a = '<div class="centered"><h3>Komplett ab</h3></div><div class="preisschild redbg"><div class="prei">';
or
$preisschild_a = "<div class=\"centered\"><h3>Komplett ab</h3></div><div class=\"preisschild redbg\"><div class=\"prei\">";
Make sure to do the same for $preisschild_b
.
You can also have "
inside a '
, but you can't have the same type of quotes unless first escaped with \
.
Also, to echo variables, you don't have to put them in quotes. eg:
<?php echo $preisschild_a; ?>
<?php echo $preis_pult; ?>
<?php echo $preisschild_b; ?>
You can put them in double quotes and they will parse normally, but will not do in single quotes.
eg:
<?php echo '$test';?> //$test
First you need something like this:
<?php
$preisschild_a = "<div class=\"centered\"><h3>Komplett ab</h3></div><div class=\"preisschild redbg\"><div class=\"preis\">";
$preis_neo = "1.000,- €";
$preis_vision55 = "1.000,- €";
$preis_vision80 = "1.000,- €";
$preis_pult = "3.699,- €";
$preis_ultra = "1.000,- €";
$preis_beamcase = "1.000,- €";
$preisschild_b = "</div><div class=\"preis-subline\">zzgl. MWST</div></div><div class=\"centered\"><h3>Infos und Bestellung:</h3><span class=\"rot block\"><h3>05252/9778511</h3></span></div><hr>";
?>
And after, when you echo:
<?php echo $preisschild_a; ?>
<?php echo $preis_pult; ?>
<?php echo $preisschild_b; ?>
(without quotes: " or ')
Mashup with double
and single
quotes
;
Replace all "
with '
in all div elements
Use this
<?php
$preisschild_a = "<div class='centered'><h3>Komplett ab</h3></div><div class='preisschild redbg'><div class='preis'>";
$preis_neo = "1.000,- €";
$preis_vision55 = "1.000,- €";
$preis_vision80 = "1.000,- €";
$preis_pult = "3.699,- €";
$preis_ultra = "1.000,- €";
$preis_beamcase = "1.000,- €";
$preisschild_b = "</div><div class='preis-subline'>zzgl. MWST</div></div><div class='centered'><h3>Infos und Bestellung:</h3><span class='rot block'><h3>05252/9778511</h3></span></div><hr>";
?>