There's no is_char function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chuck

    There's no is_char function

    I'm scanning email files and I've got a script that checks
    to see if column 1 is a char (a-z) and the word ends with
    a ":" - UgggggggggggggL E. Sure would be nice if I could
    $x = explode (" ", $line)
    if (is_chr($x[0])
    if (strstr($x, ":")
    --still in header--


    anyone have a better way?
    Tka

  • Pedro Graca

    #2
    Re: There's no is_char function

    chuck wrote:[color=blue]
    > I'm scanning email files and I've got a script that checks
    > to see if column 1 is a char (a-z) and the word ends with
    > a ":" - UgggggggggggggL E. Sure would be nice if I could
    > $x = explode (" ", $line)
    > if (is_chr($x[0])
    > if (strstr($x, ":")
    > --still in header--
    >
    >
    > anyone have a better way?[/color]

    Try Regular Expressions

    Regular Expressions (Perl-Compatible)




    Happy Coding :)

    --
    USENET would be a better place if everybody read: : mail address :
    http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
    http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
    http://www.expita.com/nomime.html : to 10K bytes :

    Comment

    • Chung Leong

      #3
      Re: There's no is_char function

      "chuck" <chuck-noapam@liderbug .com> wrote in message
      news:Nkesc.1039 $oE3.114234@new s.uswest.net...[color=blue]
      > I'm scanning email files and I've got a script that checks
      > to see if column 1 is a char (a-z) and the word ends with
      > a ":" - UgggggggggggggL E. Sure would be nice if I could
      > $x = explode (" ", $line)
      > if (is_chr($x[0])
      > if (strstr($x, ":")
      > --still in header--
      >[/color]

      The function you're looking for is ctype_alpha(). Naturally, regular
      Expression is a better solution.


      Comment

      • Webservant Alec

        #4
        Re: There's no is_char function

        chuck wrote:
        [color=blue]
        > I'm scanning email files and I've got a script that checks
        > to see if column 1 is a char (a-z) and the word ends with
        > a ":" - UgggggggggggggL E. Sure would be nice if I could
        > $x = explode (" ", $line)
        > if (is_chr($x[0])
        > if (strstr($x, ":")
        > --still in header--
        >
        >
        > anyone have a better way?
        > Tka
        >[/color]

        Not sure what "the word ends with a ':'" means.

        To see if a string ($str) starts with a-z, you can do:

        if (preg_match("/^[a-z]/", $str)) {
        // column 1 is a character
        }

        To see if a string ends with a ":" you can do:

        if (substr($str, -1) == ':') {
        // ends with a ":"
        }

        For the char thing, you could, in general, use this:

        function is_char($c) {
        if (strlen($c) == 1 && preg_match("/[a-z]/", $c)) {
        // to allow capitals, use "/[a-zA-Z]/"
        return TRUE;
        }
        return FALSE;
        }

        --
        Dedicated to the impartation of arguable expertise

        Comment

        Working...