ASP2PHP Function List Reference

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

    ASP2PHP Function List Reference

    I am new to PHP so I thought I would make a Reference List of some of
    the functions.
    Below is what I have so far.



    ASP Functions PHP Functions
    =============== ===== ===============
    Left(str,length ) substr(str,star t,length)
    Right(str,lengt h) substr(str,star t,length)
    Mid(str,start,s top) substr(str,star t,length)
    Len(str) strlen(str)
    Trim(str) trim(str)
    LTrim(str) ltrim(str)
    RTrim(str) rtrim(str)
    UCase(str) strtoupper(str)
    LCase(str) strtolower(str)
    InStr(str,value ) ---DON'T KNOW---

  • Justin Koivisto

    #2
    Re: ASP2PHP Function List Reference

    T.Taylor wrote:[color=blue]
    > I am new to PHP so I thought I would make a Reference List of some of
    > the functions.
    > Below is what I have so far.
    >
    > ASP Functions PHP Functions
    > =============== ===== ===============
    > Left(str,length ) substr(str,star t,length)
    > Right(str,lengt h) substr(str,star t,length)
    > Mid(str,start,s top) substr(str,star t,length)[/color]

    Is the stop parameter the length, or the last character's position? That
    may make a bit of difference...

    For instance (I'm about to attempt this, so please forgive me...):
    <%
    dim MyStr as String, NewStr as String
    MyStr = "This is my string"

    NewStr = Mid(MyStr,3,7)
    %>

    if NewStr ends up to be "s is my" then that is equivalent. (I'm not sure
    on this as I don't use asp)
    [color=blue]
    > Len(str) strlen(str)
    > Trim(str) trim(str)
    > LTrim(str) ltrim(str)
    > RTrim(str) rtrim(str)
    > UCase(str) strtoupper(str)
    > LCase(str) strtolower(str)
    > InStr(str,value ) ---DON'T KNOW---[/color]

    what does InStr do? maybe something like strstr ?

    --
    Justin Koivisto, ZCE - justin@koivi.co m

    Comment

    • NC

      #3
      Re: ASP2PHP Function List Reference

      T.Taylor wrote:[color=blue]
      >
      > ASP Functions PHP Functions
      > =============== ===== ===============[/color]
      ....[color=blue]
      > InStr(str,value ) ---DON'T KNOW---[/color]

      strpos(haystack , needle)

      See http://www.php.net/strpos for details.

      Cheers,
      NC

      Comment

      • Justin Koivisto

        #4
        Re: ASP2PHP Function List Reference

        T.Taylor wrote:[color=blue]
        > I am new to PHP so I thought I would make a Reference List of some of
        > the functions.
        > Below is what I have so far.[/color]

        A Programming reference comparing syntax and functions of ASP VBScript to PHP 4.3+.


        --
        Justin Koivisto, ZCE - justin@koivi.co m

        Comment

        • David Haynes

          #5
          Re: ASP2PHP Function List Reference

          T.Taylor wrote:[color=blue]
          > I am new to PHP so I thought I would make a Reference List of some of
          > the functions.
          > Below is what I have so far.
          >
          >
          >
          > ASP Functions PHP Functions
          > =============== ===== ===============
          > Left(str,length ) substr(str,star t,length)
          > Right(str,lengt h) substr(str,star t,length)
          > Mid(str,start,s top) substr(str,star t,length)
          > Len(str) strlen(str)
          > Trim(str) trim(str)
          > LTrim(str) ltrim(str)
          > RTrim(str) rtrim(str)
          > UCase(str) strtoupper(str)
          > LCase(str) strtolower(str)
          > InStr(str,value ) ---DON'T KNOW---
          >[/color]
          It might be clearer as follows:

          Left(str, length) <=> substr(str, 0, length)
          Right(str, length) <=> substr(str, strlen(str)-length)
          Mid(str, start, stop) <=> substr(str, start, (stop-start+1))

          You could always create a function to match the ASP one:

          function Left($str, $length) {
          return substr($str, 0, $length);
          }

          and so on...

          -david-

          Comment

          • T.Taylor

            #6
            Re: ASP2PHP Function List Reference

            The stop parameter is the last character's position not the length.

            Example:
            =======
            str="hello"
            Mid(str,2,4) would equal "ell"

            InStr is function that returns the start position in a string where it
            found the value otherwise is returns 0

            Example:
            ========
            str="hello"
            value1="he"
            value2 ="ll"
            value3="low"

            InStr(str,value 1) would return 1 as the position it found the value
            string starting location
            InStr(str,value 2) would return 3; the starting position of the value in
            the string
            InStr(str,value 3) would return 0; because it couldn't find the value in
            the string

            Comment

            • T.Taylor

              #7
              Re: ASP2PHP Function List Reference

              Thanks to all for the help.

              Comment

              • Justin Koivisto

                #8
                Re: ASP2PHP Function List Reference

                T.Taylor wrote:[color=blue]
                > The stop parameter is the last character's position not the length.
                >
                > Example:
                > =======
                > str="hello"
                > Mid(str,2,4) would equal "ell"[/color]

                In that case Mid is this:
                substr($str,$st art-1,$stop-$start+1);

                ....or use this:
                function Mid($str,$first ,$last){
                return substr($str,$fi rst-1,$last-$first+1);
                }
                [color=blue]
                > InStr is function that returns the start position in a string where it
                > found the value otherwise is returns 0[/color]

                function InStr($str,$sea rch){
                if(FALSE===$x=s trpos($str,$sea rch)){
                return 0;
                }else{
                return $x+1;
                }
                }

                --
                Justin Koivisto, ZCE - justin@koivi.co m

                Comment

                • Mladen Gogala

                  #9
                  Re: ASP2PHP Function List Reference

                  On Wed, 25 Jan 2006 09:03:26 -0800, T.Taylor wrote:
                  [color=blue]
                  > InStr(str,value ) ---DON'T KNOW-[/color]

                  int preg_match ( string pattern, string subject [, array &matches [, int
                  flags [, int offset]]] )

                  --


                  Comment

                  • Jim Michaels

                    #10
                    Re: ASP2PHP Function List Reference


                    "T.Taylor" <taylort2@juno. com> wrote in message
                    news:1138215417 .551296.214220@ g47g2000cwa.goo glegroups.com.. .[color=blue]
                    > The stop parameter is the last character's position not the length.
                    >
                    > Example:
                    > =======
                    > str="hello"
                    > Mid(str,2,4) would equal "ell"
                    >
                    > InStr is function that returns the start position in a string where it
                    > found the value otherwise is returns 0
                    >
                    > Example:
                    > ========
                    > str="hello"
                    > value1="he"
                    > value2 ="ll"
                    > value3="low"
                    >
                    > InStr(str,value 1) would return 1 as the position it found the value
                    > string starting location
                    > InStr(str,value 2) would return 3; the starting position of the value in
                    > the string
                    > InStr(str,value 3) would return 0; because it couldn't find the value in
                    > the string
                    >[/color]

                    in that case, InStr sounds like
                    int strpos ( string haystack, mixed needle [, int offset] )
                    int stripos ( string haystack, string needle [, int offset] )
                    int strripos ( string haystack, string needle [, int offset] )
                    int strrpos ( string haystack, string needle [, int offset] )
                    where offset is optional. strpos is a forward-direction search,
                    case-sensitive.
                    the i in the function name means a case-insensitive search. the r in the
                    function name means a reverse-direction search from the end of the string.
                    strpos returns the numeric position of the first occurrence of needle in the
                    haystack string. Unlike the strrpos(), this function can take a full string
                    as the needle parameter and the entire string will be used.

                    If needle is not found, strpos() will return boolean FALSE.

                    PHP gets its string functions from the standard C library plus a bunch more.
                    you will find them fairly powerful. there is even a tokenizer strtok() and
                    something that returns the MD5 hash of a string md5().

                    look up printf(). you can format a string or number almost any way you like
                    with it. and numbers don't get leading spaces in them like vb puts in.

                    strtr() does a character translation.

                    soundex() calculates the soundex key of a string for sounds-like searches.

                    if you know how to use regular expressions, they are very powerful for doing
                    complicated search-and-replace work on text. see preg_replace() and
                    preg_match()

                    see http://www.php.net/manual/en/ref.strings.php for a starter.


                    Comment

                    • Jim Michaels

                      #11
                      Re: ASP2PHP Function List Reference


                      "Mladen Gogala" <gogala@sbcglob al.net> wrote in message
                      news:pan.2006.0 1.26.13.08.34.1 8737@sbcglobal. net...[color=blue]
                      > On Wed, 25 Jan 2006 09:03:26 -0800, T.Taylor wrote:
                      >[color=green]
                      >> InStr(str,value ) ---DON'T KNOW-[/color]
                      >
                      > int preg_match ( string pattern, string subject [, array &matches [, int
                      > flags [, int offset]]] )[/color]

                      that's a nice function, but not a proper replacement. strpos is the fit.
                      [color=blue]
                      >
                      > --
                      > http://www.mgogala.com
                      >[/color]


                      Comment

                      • Jim Michaels

                        #12
                        Re: ASP2PHP Function List Reference


                        "T.Taylor" <taylort2@juno. com> wrote in message
                        news:1138208606 .877180.20140@o 13g2000cwo.goog legroups.com...[color=blue]
                        >I am new to PHP so I thought I would make a Reference List of some of
                        > the functions.
                        > Below is what I have so far.
                        >
                        >
                        >
                        > ASP Functions PHP Functions
                        > =============== ===== ===============
                        > Left(str,length ) substr(str,star t,length)
                        > Right(str,lengt h) substr(str,star t,length)
                        > Mid(str,start,s top) substr(str,star t,length)[/color]

                        I don't think the statement for Mid() is correct. if it was anything like
                        Mid$, Mid$ was Mid$(str, start[,length]). Microsoft probably hasn't changed
                        their string syntax since their first BASIC language came out - BASIC-80 I
                        think it was.
                        it seems to me I also Mid(str,start) is probably available as an option.
                        substr(str,star t) is the replacement.
                        and any time you want to access character #6 of a string in PHP, $string{5}
                        is how you access it.

                        You must remember that in PHP, strings are indexed starting from 0. In VB,
                        they are indexed starting at 1. this is key.
                        So in ASP, start and stop are 1-based. in PHP, start and stop are 0-based.

                        [color=blue]
                        > Len(str) strlen(str)
                        > Trim(str) trim(str)
                        > LTrim(str) ltrim(str)
                        > RTrim(str) rtrim(str)
                        > UCase(str) strtoupper(str)
                        > LCase(str) strtolower(str)
                        > InStr(str,value ) ---DON'T KNOW---
                        >[/color]


                        Comment

                        • Jasen Betts

                          #13
                          Re: ASP2PHP Function List Reference

                          On 2006-02-07, Jim Michaels <jmichae3@nospa m.yahoo.com> wrote:
                          [color=blue]
                          > look up printf(). you can format a string or number almost any way you like
                          > with it. and numbers don't get leading spaces in them like vb puts in.[/color]

                          unless you want them... %-g
                          [color=blue]
                          > strtr() does a character translation.
                          >
                          > soundex() calculates the soundex key of a string for sounds-like searches.
                          >
                          > if you know how to use regular expressions, they are very powerful for doing
                          > complicated search-and-replace work on text. see preg_replace() and
                          > preg_match()[/color]

                          Also ereg_replace and ereg_match if you prefer POSIX extended RE's over PERL.

                          Bye.
                          Jasen

                          Comment

                          Working...