为什么我的PHP echo()命令不能按预期工作?
我调用一个我知道子字符串存在的函数,而echo命令将无法按我希望的方式工作 它似乎总是呼应字符串说它不存在。对于本例,我们可以将其设置为键为什么我的PHP echo()命令不能按预期工作?,php,html,Php,Html,我调用一个我知道子字符串存在的函数,而echo命令将无法按我希望的方式工作 它似乎总是呼应字符串说它不存在。对于本例,我们可以将其设置为键 $KEY = "R1*PFD1V1FE1VS1BF1SP1NL2OW1TP1MSD1NR1"; function displayNL( $KEY ) { switch ( true ) { case ( is_numeric( strpos($KEY, 'NL1') ) ) : echo "Masthead
$KEY = "R1*PFD1V1FE1VS1BF1SP1NL2OW1TP1MSD1NR1";
function displayNL( $KEY ) {
switch ( true ) {
case ( is_numeric( strpos($KEY, 'NL1') ) ) :
echo "Masthead Light: May replace with Electric Torch or Lantern Sidelights: May replace with Electric Torch or Lantern Sternlight: May replace with Electric Torch or Lantern Other Lights: - Dayshapes: - ";
break;
case ( is_numeric ( strpos($KEY, 'NL2') ) ) :
echo "Masthead Light: May replace with Electric Torch or Lantern Sidelights: May replace with Electric Torch or Lantern Sternlight: May replace with Electric Torch or Lantern Other Lights: All Around Red over All Around Green on Masthead (OPTIONAL) Dayshapes: -" ;
break;
case ( is_numeric ( strpos($KEY, 'NL3') ) ) :
echo "Masthead Light: May replace with Electric Torch or Lantern Sidelights: May replace with Electric Torch or Lantern Sternlight: May replace with Electric Torch or Lantern Other Lights: All Around Red over All Around Green on Masthead (OPTIONAL) Dayshapes: When under power and in International Waters, Cone with Apex Down" ;
break;
case ( is_numeric ( strpos($KEY, 'NL4') ) ) :
echo "Masthead Light: May replace with All Around White Light Sidelights: May forego if impracticle to mount Sternlight: May replace with Other Lights: All Around White Light - Dayshapes: - " ;
break;
case ( is_numeric ( strpos($KEY, 'NL5') ) ) :
echo "Masthead Light: May replace with All Around White Light Sidelights: May have Sidelights Combined in Single Lantern on Centerline Sternlight: May replace with Other Lights: All Around White Light - Dayshapes: - " ;
break;
case ( is_numeric ( strpos($KEY, 'NL6') ) ) :
echo "Masthead Light: Masthead Light Not Required Sidelights: May have Single Lantern with Sidelights and Sternlights on Mast Sternlight: May have Single Lantern with Sidelights and Sternlights on Mast Other Lights: All Around Red over All Around Green on Masthead (OPTIONAL) Dayshapes: - " ;
break;
case ( is_numeric ( strpos($KEY, 'NL7') ) ) :
echo "Masthead Light: Masthead Light Not Required Sidelights: May have Single Lantern with Sidelights and Sternlights on Mast Sternlight: May have Single Lantern with Sidelights and Sternlights on Mast Other Lights: All Around Red over All Around Green on Masthead (OPTIONAL) Dayshapes: When under power and in International Waters, Cone with Apex Down " ;
break;
case ( is_numeric ( strpos($KEY, 'NL8') ) ) :
echo "Masthead Light: Required Sidelights: May have Sidelights Combined in Single Lantern on Centerline Sternlight: Required Other Lights: - Dayshapes: - " ;
break;
case ( is_numeric ( strpos($KEY, 'NL9') ) ) :
echo "Masthead Light: Required Sidelights: Required Sternlight: Required Other Lights: - Dayshapes: - " ;
break;
case ( is_numeric ( strpos($KEY, 'NL1*0') ) ) :
echo "Masthead Light: Required Sidelights: Required Sternlight: Required Other Lights: All Around Red over All Around Green on Masthead Dayshapes: - " ;
break;
case ( is_numeric ( strpos($KEY, 'NL1*1') ) ) :
echo "Masthead Light: Required Sidelights: Required Sternlight: Required Other Lights: All Around Red over All Around Green on Masthead Dayshapes: When under power, Cone with Apex Down " ;
break;
case ( is_numeric ( strpos($KEY, 'NL1*2') ) ) :
echo "Masthead Light: Required, 2 Sidelights: Required Sternlight: Required Other Lights: - Dayshapes: - " ;
break;
case ( is_numeric ( strpos($KEY, 'NL1*3') ) ) :
echo "Masthead Light: Required, 2 Sidelights: Required Sternlight: Required Other Lights: All Around Red over All Around Green on Masthead Dayshapes: - " ;
break;
case ( is_numeric ( strpos($KEY, 'NL1*4') ) ) :
echo "Masthead Light: Required, 2 Sidelights: Required Sternlight: Required Other Lights: All Around Red over All Around Green on Masthead Dayshapes: When under power, Cone with Apex Down " ;
break;
default:
echo "Make sure you selected somthing OR This Combination Does Not Exists ";
}
}
displayNL( $KEY ) ;
这对我来说很有效…我想这个bug是在别的地方。如果它没有返回任何内容,则尝试使用die('break')调试代码;在此代码块之前。这是可以用来识别bug的最简单的调试方法
如果骰子不工作,则代码块上方会出现错误。您的代码正在滥用开关,以获得数组或一组ifs更好的服务。另外,NL1*0永远不会发生,因为它只会被NL1捕获。您的
strpos('KEY,'NL2')
返回什么?我会快速检查这是奇怪的代码。无论开关
的用法如何,strpos
检查都是错误的,因为您需要在中对其进行检查==FALSE
是一些数字。它没有返回任何内容。它只是一片空白