1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Buying Look for a very simple custom script

Discussion in 'Programming' started by Matthew Sayle, Jan 2, 2016.

  1. #1
    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!
     
    Matthew Sayle, Jan 2, 2016 IP
  2. cLogik

    cLogik Active Member

    Messages:
    159
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    90
    As Seller:
    100% - 0
    As Buyer:
    100% - 1
    #2
    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, Jan 2, 2016 IP
    FreeFun4Every1 and Matthew Sayle like this.
  3. Matthew Sayle

    Matthew Sayle Prominent Member

    Messages:
    3,325
    Likes Received:
    464
    Best Answers:
    1
    Trophy Points:
    385
    As Seller:
    100% - 25
    As Buyer:
    81.8% - 9
    #3
    @cLogik

    Thanks for the snippet.

    Am I missing something?

    There is nowhere to enter the string on the website.
     
    Last edited: Jan 2, 2016
    Matthew Sayle, Jan 2, 2016 IP
  4. Matthew Sayle

    Matthew Sayle Prominent Member

    Messages:
    3,325
    Likes Received:
    464
    Best Answers:
    1
    Trophy Points:
    385
    As Seller:
    100% - 25
    As Buyer:
    81.8% - 9
    #4
    I am testing it on MattSayle.com, if that helps.
     
    Matthew Sayle, Jan 2, 2016 IP
  5. KangBroke

    KangBroke Notable Member

    Messages:
    1,026
    Likes Received:
    59
    Best Answers:
    4
    Trophy Points:
    265
    As Seller:
    100% - 6
    As Buyer:
    100% - 7
    #5
    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';}
    ?>
     
    KangBroke, Jan 2, 2016 IP
  6. Matthew Sayle

    Matthew Sayle Prominent Member

    Messages:
    3,325
    Likes Received:
    464
    Best Answers:
    1
    Trophy Points:
    385
    As Seller:
    100% - 25
    As Buyer:
    81.8% - 9
    #6
    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?
     
    Matthew Sayle, Jan 2, 2016 IP
  7. KangBroke

    KangBroke Notable Member

    Messages:
    1,026
    Likes Received:
    59
    Best Answers:
    4
    Trophy Points:
    265
    As Seller:
    100% - 6
    As Buyer:
    100% - 7
    #7
    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";}
    ?>
     
    Last edited by a moderator: Jan 3, 2016
    KangBroke, Jan 2, 2016 IP
    Matthew Sayle likes this.
  8. Dangy

    Dangy Well-Known Member

    Messages:
    841
    Likes Received:
    25
    Best Answers:
    2
    Trophy Points:
    155
    As Seller:
    100% - 1
    As Buyer:
    100% - 0
    #8
    <?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.
     
    Last edited: Jan 3, 2016
    Dangy, Jan 3, 2016 IP
    FreeFun4Every1 likes this.