strpos command breaking php program
Get the solution ↓↓↓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>";
}
?>
Answer
Solution:
There's nothing wrong with the way you callstrpos()
. 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,
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: warning: a non-numeric value encountered in
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.