douxun4860 2019-03-15 00:35
浏览 64
已采纳

strpos命令打破php程序

I have been working on a madlibs program, and it has been breaking for no reason it seems like. I take user input from an html form. I am trying to check if the user input is valid. In order for the data to be valid, the data must NOT contain a space, or any punctuation character. I am not sure if I should use the strpos command, or preg_match. Anyway I am able to get to the first if statement, and it breaks. I have used multiple variations of this command, and no matter what I do my code seems to break. All I am trying to do is check if this consolidated string contains a single char. It seems simple enough, but I cannot seem to find the issue. Any responses would be greatly appreciated. I can post the code from my html page, but the problem does not lie in that code.

<?php
//Michael Keller
//Project1

//Variables
$stringFirstVerb = $_POST["stringFirstVerb"];       
$stringSecondVerb = $_POST["stringSecondVerb"];   
$stringThirdVerb = $_POST["stringThirdVerb"];        
$stringFirstNoun = $_POST["stringFirstNoun"];      
$stringSecondNoun = $_POST["stringSecondNoun"];     
$stringThirdNoun = $_POST["stringThirdNoun"];   
$stringFirstAdj = $_POST["stringFirstAdj"];    
$stringSecondAdj = $_POST["stringSecondAdj"];
$stringThirdAdj = $_POST["stringThirdAdj"];          
$stringParagraph = $_POST["stringParagraph"];         
$intNounCount = 0;
$intVerbCount= 0;
$intAdjCount = 0;
//check for user input
$stringNewStr = implode("",array($stringFirstVerb,$stringSecondVerb,
$stringThirdVerb,$stringFirstNoun,$stringSecondNoun,$stringThirdNoun,
$stringFirstAdj,$stringSecondAdj,$stringThirdAdj));   

var_dump($stringNewStr);

if( strpos($stringNewStr, ' ' ) !== false ){
echo "No spaces allowed in any Verbs, Nouns, or Adj's";
echo "<br>";
echo "<a href="project1.html">Link to previous Page</a>";
}
?>
  • 写回答

1条回答 默认 最新

  • dongzhong9055 2019-03-15 03:33
    关注

    There's nothing wrong with the way you call strpos(). You have a syntax error:

    echo "<a href="project1.html">Link to previous Page</a>";
    

    should be:

    echo "<a href='project1.html'>Link to previous Page</a>";
    

    Hope this helps,

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

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统