ASP2PHP Function List Reference 
January 25th, 2006, 04:15 PM
| | | 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,start,length)
Right(str,length) substr(str,start,length)
Mid(str,start,stop) substr(str,start,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--- | 
January 25th, 2006, 04:25 PM
| | | 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,start,length)
> Right(str,length) substr(str,start,length)
> Mid(str,start,stop) substr(str,start,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.com http://koivi.com | 
January 25th, 2006, 04:55 PM
| | | 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 | 
January 25th, 2006, 05:35 PM
| | | 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,start,length)
> Right(str,length) substr(str,start,length)
> Mid(str,start,stop) substr(str,start,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- | 
January 25th, 2006, 06:05 PM
| | | 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,value1) would return 1 as the position it found the value
string starting location
InStr(str,value2) would return 3; the starting position of the value in
the string
InStr(str,value3) would return 0; because it couldn't find the value in
the string | 
January 25th, 2006, 06:55 PM
| | | Re: ASP2PHP Function List Reference
Thanks to all for the help. | 
January 25th, 2006, 06:55 PM
| | | 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,$start-1,$stop-$start+1);
....or use this:
function Mid($str,$first,$last){
return substr($str,$first-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,$search){
if(FALSE===$x=strpos($str,$search)){
return 0;
}else{
return $x+1;
}
}
--
Justin Koivisto, ZCE - justin@koivi.com http://koivi.com | 
January 26th, 2006, 12:15 PM
| | | 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]]] )
-- http://www.mgogala.com | 
February 7th, 2006, 08:25 AM
| | | Re: ASP2PHP Function List Reference
"T.Taylor" <taylort2@juno.com> wrote in message
news:1138215417.551296.214220@g47g2000cwa.googlegr oups.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,value1) would return 1 as the position it found the value
> string starting location
> InStr(str,value2) would return 3; the starting position of the value in
> the string
> InStr(str,value3) 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. | 
February 7th, 2006, 08:25 AM
| | | Re: ASP2PHP Function List Reference
"Mladen Gogala" <gogala@sbcglobal.net> wrote in message
news:pan.2006.01.26.13.08.34.18737@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] | 
February 7th, 2006, 06:55 PM
| | | Re: ASP2PHP Function List Reference
"T.Taylor" <taylort2@juno.com> wrote in message
news:1138208606.877180.20140@o13g2000cwo.googlegro ups.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,start,length)
> Right(str,length) substr(str,start,length)
> Mid(str,start,stop) substr(str,start,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,start) 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] | 
February 8th, 2006, 10:25 AM
| | | Re: ASP2PHP Function List Reference
On 2006-02-07, Jim Michaels <jmichae3@nospam.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 | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 220,989 network members.
|