I need a script that can detect whether or not there is a hyphen in a string of text. For example, if someone pastes 'jiuh43h3oihj34io5u345u74070' = It will come back with 'there are no hyphens'. However, if they post 'ffjhfjkjjhjk-jhfjhjfhfh' = it will come back 'hyphen detected'. The exact message echoed during the 2 scenarios will be different than the example, but this is the basic outline. We will discuss the exact details in private - however the core functionality will be detecting a hyphen in a string of text. It doesn't need to count them, it doesn't need to figure out where the hyphen is, all it needs to do is display a positive or negative message if it detects a hyphen. Waiting for your bid and TOT!
This isn't a script, but a single piece of code and function. $string = 'Thisismydamnwordandicantypewhatiwant" if( strpos( $string, '-' ) !== false ) { echo 'Hyphen detected'; } else { echo 'Hyphen not found'; } PHP: Happy codin!
@cLogik Thanks for the snippet. Am I missing something? There is nowhere to enter the string on the website.
from the looks of it your missing the <?php at the beginning and the ?> at the end. But I can assist you into making a form so that you can input a new string <?php $string = 'Thisismydamnwordandicantypewhatiwant'; if(strpos($string,'-')!==false) { echo 'Hyphen detected';} else {echo 'Hyphen not found';} ?>
I added that already. Out of curiosity, why go through the trouble posting a message here requesting that I send you a PM? Why wouldn't you just PM me?
The idea behind that is so that you PM me if you still need help. If not you wont get any wasted inbox messages. From looking at your page outputting the code the way it is, your missing those. Also missing a ; behind the variable. This should work <?php $string = "Thisismydamnwordandicantypewhatiwant"; if(strpos($string,'-')!==false) { echo "Hyphen detected";} else {echo "Hyphen not found";} ?>
<?php function fhypen($string){ if( strpos( $string, '-' ) !== false ) { echo 'Hyphen Found'; } else { echo 'Hyphen Missing'; } } if(isset($_POST['SubmitButton'])){ //check if form was submitted $input = $_POST['inputText']; //get input text $message = fhypen($input); } ?> <html> <body> <form action="" method="post"> <?php echo $message; ?> <input type="text" name="inputText"/> <input type="submit" name="SubmitButton"/> </form> </body> </html> Code (markup): An if this gets posted to a database your going to wanna add security.