Php if-else语句中的多字符串错误
Value1和Value3正在检索True,因为Random 1.5在字符串中具有。如何解决这个问题?我只想发布粗体随机1.5值。谢谢你的帮助 您正在进行精确的字符串匹配,而不是子字符串匹配,因此,除非$title值与if语句中的字符串完全相同,否则random 1.5和bold random 1.5将无法匹配相同的字符串 e、 g 但是如果你有Php if-else语句中的多字符串错误,php,if-statement,Php,If Statement,Value1和Value3正在检索True,因为Random 1.5在字符串中具有。如何解决这个问题?我只想发布粗体随机1.5值。谢谢你的帮助 您正在进行精确的字符串匹配,而不是子字符串匹配,因此,除非$title值与if语句中的字符串完全相同,否则random 1.5和bold random 1.5将无法匹配相同的字符串 e、 g 但是如果你有 $teststring = 'Random 1.5'; ($teststring == 'Random 1.5') // evaluates to
$teststring = 'Random 1.5';
($teststring == 'Random 1.5') // evaluates to TRUE
($teststring == 'Bold Random 1.5') // evaluates to FALSE
两者都会成功,因为“Random 1.5”显示在正在搜索的两个字符串中
同样,由于您反复测试一个变量对多个值,请考虑使用一个开关代替:
strpos('Random 1.5', $teststring) // integer 0 result, not boolean false
strpos('Bold Random 1.5', $teststring) // integer 4 result, not boolean false
这是什么语言?php?谢谢你的帮助。干得好。
strpos('Random 1.5', $teststring) // integer 0 result, not boolean false
strpos('Bold Random 1.5', $teststring) // integer 4 result, not boolean false
switch($title) {
case 'Random 1.5': $ytitle = 'Custom 1.5'; break;
case 'Another 1.6': $ytitle = 'Custom 1.6'; break;
case 'Bold Random 1.5': $ytitle = 'Custom 1.7'; break;
}