473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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---

Jan 25 '06 #1
12 1692
T.Taylor wrote:
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)
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)
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---


what does InStr do? maybe something like strstr ?

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Jan 25 '06 #2
NC
T.Taylor wrote:

ASP Functions PHP Functions
==================== =============== .... InStr(str,value) ---DON'T KNOW---


strpos(haystack, needle)

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

Cheers,
NC

Jan 25 '06 #3
T.Taylor wrote:
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.


http://design215.com/toolbox/asp.php

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Jan 25 '06 #4
T.Taylor wrote:
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---

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-

Jan 25 '06 #5
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

Jan 25 '06 #6
Thanks to all for the help.

Jan 25 '06 #7
T.Taylor wrote:
The stop parameter is the last character's position not the length.

Example:
=======
str="hello"
Mid(str,2,4) would equal "ell"
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);
}
InStr is function that returns the start position in a string where it
found the value otherwise is returns 0


function InStr($str,$search){
if(FALSE===$x=strpos($str,$search)){
return 0;
}else{
return $x+1;
}
}

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Jan 25 '06 #8
On Wed, 25 Jan 2006 09:03:26 -0800, T.Taylor wrote:
InStr(str,value) ---DON'T KNOW-


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

--
http://www.mgogala.com

Jan 26 '06 #9

"T.Taylor" <ta******@juno.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
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


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.
Feb 7 '06 #10

"Mladen Gogala" <go****@sbcglobal.net> wrote in message
news:pa***************************@sbcglobal.net.. .
On Wed, 25 Jan 2006 09:03:26 -0800, T.Taylor wrote:
InStr(str,value) ---DON'T KNOW-
int preg_match ( string pattern, string subject [, array &matches [, int
flags [, int offset]]] )


that's a nice function, but not a proper replacement. strpos is the fit.

--
http://www.mgogala.com

Feb 7 '06 #11

"T.Taylor" <ta******@juno.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
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)
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.

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---

Feb 7 '06 #12
On 2006-02-07, Jim Michaels <jm******@nospam.yahoo.com> wrote:
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.
unless you want them... %-g
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()


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

Bye.
Jasen
Feb 8 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
6
by: NKOBAYE027 | last post by:
FIRST POST Hi All: I'm trying to write a simple specialization before moving on to something a bit more complex - always a good idea in my case, at least. :o) I'm trying to adapt the example...
20
by: Gregory Piñero | last post by:
Hey guys, would someone mind giving me a quick rundown of how references work in Python when passing arguments into functions? The code below should highlight my specific confusion: <code> ...
2
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a...
9
by: ogerchikov | last post by:
I have 2 classes, A, B and B is a child of A. and I have a function which processes a list of A. void func(list<A> alist) { // processing list of A } The problem is func() won't able to...
1
by: cognominal | last post by:
I am using fifrefox 1.5.0.2 and I have modified the javascript shell to deal with e4x. Below is a session. I would have expected <toto/>.nodeKind to be of type "function". Is this right? Is...
6
by: Jack White | last post by:
Does anyone know if an analogue to the "swap()" function found in C++ exists in C#. For those not familiar, let's say you have a function that loads some collection passed in by reference. If an...
3
by: Ray D. | last post by:
Hey all, I'm trying to pass a list into a function to edit it but when I compile using g++ I continue to get the following error: maintainNeighbors.cpp:104: error: invalid initialization of...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.