duanhe3393 2018-10-05 14:42
浏览 33
已采纳

too long

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, &quot;Helvetica Neue&quot;, Helvetica, sans-serif with the extra &quot; 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...";
    }
 ?>
  • 写回答

1条回答 默认 最新

  • dsfvsdfv23599 2018-10-05 16:11
    关注

    It appears you've inserted HTML encoded values into your database. Don't do this.

    You should be HTML encoding stuff on OUTPUT not INPUT.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答