Ok so I am pulling what kind of font is used from my database that is saved from a previous form. My issue is that even when I 100% replicate what I echo to come from bodyFont it will not compare and just drop to the else statement of error. What in the world is causing this? Can it be the fact that I have " and ,? Any help would be awesome. (I have to use the full name Arial, "Helvetica Neue", Helvetica, sans-serif ETC for what I am doing.
NOTE:
JUST FYI - I have my connection and everything that's not the code giving me a issue, I can pull from the database and also used the same if statement to work for header font but that simply uses words no , or " in names.
<?php
echo "$bodyFont";
if ($bodyFont == 'Arial, "Helvetica Neue", Helvetica, sans-serif') {
echo "
1
";
} elseif ($bodyFont == '"Times New Roman", Times, serif') {
echo "
2
";
} else {
echo "<br />error";
}
?>
Ran Var_Dump and got the following:
string(56) "Arial, "Helvetica Neue", Helvetica, sans-serif" - PULLED FROM DATABASE
string(46) "Arial, "Helvetica Neue", Helvetica, sans-serif" - PULLED FROM VAR
56 and 46... How would this be fixed?
<?php
$one = 'Arial, "Helvetica Neue", Helvetica, sans-serif';
$bodyFontstrip = strip_tags($bodyFont);
var_dump($bodyFont);
echo "<br />";
var_dump($one);
if ($bodyFontstrip == $one) {
echo "Arial";
} else {
echo "<br />error";
}
?>
OK I SEE WHATS GOING ON:
The $bodyFont
that I pull form the server turns out as Arial, "Helvetica Neue", Helvetica, sans-serif
with the extra "
in it. I must find a way to remove this now.
To fix I did as GrumpyCrouton suggested below and used html_entity_decode($bodyFont).
FIXED WORKING CODE:
<?php
$one = 'Arial, "Helvetica Neue", Helvetica, sans-serif';
$two = '"Times New Roman", Times, serif';
$bodyFontclean = html_entity_decode($bodyFont);
var_dump($bodyFont);
echo "<br />";
var_dump($one);
echo "<br />";
var_dump($two);
if ($bodyFontclean == $one) {
echo "Arial";
} elseif ($bodyFontclean == $two){
echo "Times";
} else {
echo "error...";
}
?>