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,

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

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀