php pattern problem for xxxxxx-xx-xxxx using all digits

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fareast Adam
    New Member
    • Feb 2007
    • 51

    php pattern problem for xxxxxx-xx-xxxx using all digits

    hi all... anybody here know how to set a php pattern for xxxxxx-xx-xxxx using all digits? here is my code, is there any mistake?
    $pattic="/(\d{6})-(\d{2})-(\d{4})/";
  • xwero
    New Member
    • Feb 2007
    • 99

    #2
    Originally posted by Fareast Adam
    hi all... anybody here know how to set a php pattern for xxxxxx-xx-xxxx using all digits? here is my code, is there any mistake?
    $pattic="/(\d{6})-(\d{2})-(\d{4})/";
    have you tried "/^([0-9]{6})-([0-9]{2})-([0-9]{4})$/" ?

    It should be the same with \d but sometimes the php functions don't interpret the escaped characters.

    Comment

    • Fareast Adam
      New Member
      • Feb 2007
      • 51

      #3
      Originally posted by xwero
      have you tried "/^([0-9]{6})-([0-9]{2})-([0-9]{4})$/" ?

      It should be the same with \d but sometimes the php functions don't interpret the escaped characters.
      It look loke a charm! Thanks...

      Comment

      • Fareast Adam
        New Member
        • Feb 2007
        • 51

        #4
        Other sample, firstly i want to capture all the text from the textfield then insert into db. Before inserting into db, i have to convert all text that have been captured before into standard english grammer (first letter must be start with big caps).. How can i do that? Any idea?

        Comment

        • xwero
          New Member
          • Feb 2007
          • 99

          #5
          Originally posted by Fareast Adam
          Other sample, firstly i want to capture all the text from the textfield then insert into db. Before inserting into db, i have to convert all text that have been captured before into standard english grammer (first letter must be start with big caps).. How can i do that? Any idea?
          I think you better use css for this sort of thing. text-transform :capitalize will do the trick but if you insist on doing it the php way

          [PHP]preg_replace('/ ([a-z]{1})/', strtoupper('$1' ),$string); [/PHP]

          I haven't tested it but the though behind it is fairly simple : every first little letter after a space has to transform to a capital letter.

          Comment

          • Fareast Adam
            New Member
            • Feb 2007
            • 51

            #6
            Originally posted by xwero
            I think you better use css for this sort of thing. text-transform :capitalize will do the trick but if you insist on doing it the php way

            [PHP]preg_replace('/ ([a-z]{1})/', strtoupper('$1' ),$string); [/PHP]

            I haven't tested it but the though behind it is fairly simple : every first little letter after a space has to transform to a capital letter.
            is that like this to write?

            function convertText($te xt)
            {
            preg_replace('/ ([a-z]{1})/', strtoupper('$1' ),$text);
            }

            but how can i pass and it insert into db? is that need any return variable to do that?

            Comment

            • xwero
              New Member
              • Feb 2007
              • 99

              #7
              [PHP]
              $text = preg_replace('/ ([a-z]{1})/', strtoupper('$1' ),$text);
              [/PHP]

              Comment

              • Fareast Adam
                New Member
                • Feb 2007
                • 51

                #8
                I try this just for a testing:

                if(isset($_REQU EST['Submit']))
                {
                $text = $_POST['name'];
                $string = preg_replace('/ ([a-z]{1})/', strtoupper('$1' ),$text);
                echo $string;
                }

                but i dont achieves my point.
                ex: when i insert text "web programming" but i dont get the actual output like "Web Programming" - an output must be big caps for any first word and both word seperate with single space!

                Thanks xwero at all! I cant reply u later, just send it regards bye :p

                Comment

                • xwero
                  New Member
                  • Feb 2007
                  • 99

                  #9
                  [PHP]

                  if(isset($_REQU EST['Submit']))
                  {
                  $text = $_POST['name'];
                  // for the first letter
                  $string = preg_replace('/^([a-z]{1})/', strtoupper('$1' ),$text);
                  // for all following words
                  $string = preg_replace('/ ([a-z]{1})/', strtoupper('$1' ),$text);
                  echo $string;
                  }
                  [/PHP]

                  Which output do you get now?

                  Comment

                  • Fareast Adam
                    New Member
                    • Feb 2007
                    • 51

                    #10
                    Originally posted by xwero
                    [PHP]

                    if(isset($_REQU EST['Submit']))
                    {
                    $text = $_POST['name'];
                    // for the first letter
                    $string = preg_replace('/^([a-z]{1})/', strtoupper('$1' ),$text);
                    // for all following words
                    $string = preg_replace('/ ([a-z]{1})/', strtoupper('$1' ),$text);
                    echo $string;
                    }
                    [/PHP]

                    Which output do you get now?
                    Sorry buddy i still not get an expected result! For example i type a text "web programming" but what i get is "webprogramming ".. Do u have any idea?

                    Comment

                    • Fareast Adam
                      New Member
                      • Feb 2007
                      • 51

                      #11
                      I got the solution from http://www.weberdev.com/ViewArticle/479. Here is what i want:

                      if(isset($_REQU EST['Submit']))
                      {
                      //capture text from textfield
                      $text = $_POST['name'];

                      //function ucwords() set any first capital in any words with capital letter
                      echo ucwords($text);
                      }

                      Thanks again xwero!

                      Regards,
                      Fareast Adam

                      Comment

                      • Fareast Adam
                        New Member
                        • Feb 2007
                        • 51

                        #12
                        Here is really what i wants;

                        if(isset($_REQU EST['Submit']))
                        {
                        //capture text from textfield
                        $text = $_POST['name'];

                        //convert all text into lowercase then set all any first capital in any words with capital letters
                        //function ucwords() set any first capital in any words with capital letter
                        //function strtolower() set all text into lowercase
                        echo ucwords(strtolo wer($text));
                        }

                        Regards,
                        Fareast Adam

                        Comment

                        Working...