一、php中strpos 同 asp中  InStr :返回一个字符串在另一个字符串中首次出现的位置

InStr([start,]string1,string2[,compare])
参数 描述
start 可选的。规定每次搜索的起始位置。默认是搜索起始位置是第一个字符。如果已规定 compare 参数,则必须有此参数。
string1 必需的。需要被搜索的字符串。
string2 必需的。需搜索的字符串。
compare

必需的。规定要使用的字符串比较类型。默认是 0 。可采用下列值:

  • 0 = vbBinaryCompare - 执行二进制比较。
  • 1 = vbTextCompare - 执行文本比较。











int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )

返回 needlehaystack 中首次出现的数字位置。与 strrpos() 不同,在 PHP 5 之前,该函数可以使用一个完整字符串作为 needle,并且整个字符串都将被使用。 


参数

haystack

在该字符串中进行查找。

needle

如果 needle 不是一个字符串,那么它将被转换为整型并被视为字符的顺序值。

offset

可选的 offset 参数可以用来指定从 haystack 中的哪一个字符开始查找。返回的数字位置是相对于 haystack 的起始位置而言的。


<?php
$mystring 
'abc';
$findme   'a';
$pos strpos($mystring$findme);

// 注意这里使用的是 === 或!==。简单的 == 或 != 不能像我们期待的那样工作,
// 因为 'a' 是第 0 位置上的(第一个)字符。
if ($pos === false) {
    echo 
"The string '$findme' was not found in the string '$mystring'";
} else {
    echo 
"The string '$findme' was found in the string '$mystring'";
    echo 
" and exists at position $pos";
}
?>

C#中indexOf

String.IndexOf 方法 (Char, [startIndex], [count])

报告指定字符在此实例中的第一个匹配项的索引。搜索从指定字符位置开始,并检查指定数量的字符位置。

参数

value

要查找的 Unicode 字符。 对 value 的搜索区分大小写。

startIndex(Int32)

可选项,搜索起始位置。不设置则从0开始。

count(Int32)

可选项,要检查的字符位置数。

返回值

如果找到该字符,则为 value 的索引位置;否则如果未找到,则为 -1。


注意:php比asp多出来的:


1、int strrpos 或  strripos ( string $haystack , string $needle [, int $offset = 0 ] )

返回字符串 haystackneedle 最后一次出现的数字位置。注意 PHP4 中,needle 只能为单个字符。如果 needle 被指定为一个字符串,那么将仅使用第一个字符。( strripos不区分大小写)



2、string strstr 或  (stristr) ( string $haystack , mixed $needle [, bool $before_needle = false ] )
返回 haystack 字符串从 needle 第一次出现的位置开始到 haystack 结尾的字符串。
参数

haystack

输入字符串。

needle

如果 needle 不是一个字符串,那么它将被转化为整型并且作为字符的序号来使用。

before_needle

若为 TRUE,strstr() 将返回 needlehaystack 中的位置之前的部分。


3、string strrchr ( string $haystack , mixed $needle )

该函数返回 haystack 字符串中的一部分,这部分以 needle 的最后出现位置开始,直到 haystack 末尾。


参数

haystack

在该字符串中查找。

needle

如果 needle 包含了不止一个字符,那么仅使用第一个字符。该行为不同于 strstr()

如果 needle 不是一个字符串,那么将被转化为整型并被视为字符顺序值。


返回值

该函数返回字符串的一部分。如果 needle 未被找到,返回 FALSE


二、 php中strlen与asp中Len
php比asp多个
int mb_strlen ( string $str [, string $encoding ] ) 
参数

str

The string being checked for length.

encoding

encoding 参数为字符编码。如果省略,则使用内部字符编码。

三、大小写转化

asp中为Ucase 和 Lcase   php中为 strtolower 和 strtoupper

php中多出来的:

ucfirst将字符串的首字母转换为大写

ucwords将字符串中每个单词的首字母转换为大写



三、asp中mid 与 php中 substr

aspMid(string,start[,length])


php中:

string substr ( string $string , int $start [, int $length ] )

返回字符串 stringstartlength 参数指定的子字符串。


四、asp 中 replace 同 php中 substr_replace

Replace(string,find,replacewith[,start[,count[,compare]]])
参数 描述
string 必需的。需要被搜索的字符串。
find 必需的。将被替换的字符串部分。
replacewith 必需的。用于替换的子字符串。
start 可选的。规定开始位置。默认是 1。
count 可选的。规定指定替换的次数。默认是 -1,表示进行所有可能的替换。
compare 可选的。规定所使用的字符串比较类型。默认是 0。


mixed substr_replace ( mixed $string , string $replacement , int $start [, int $length ] )

mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] )

搜索subject中匹配pattern的部分, 以replacement进行替换.


五、asp 中 replace 同 php中 substr_replace



php特有的:
int substr_count ( string $haystack , string $needle [, int $offset = 0 [, int $length ]] )
返回子字符串needle 在字符串 haystack 中出现的次数。注意 needle 区分大小写。


php中和html标签有关的字符串格式化

nl2br();//将在把所有的回车部分加上<br>换行 htmlentities() htmlspecialchars()//转换成实体,用户输入什么就显示什么 stripslashes()//删除反斜线 htmlspecialchars(stripslashes($str)); str_tags()//删除用户输入的html标签 str_tags($str,"<b><h1>")//第二个参数保留的html标签 其他字符串格式化函数 number_format()\\千位分组格式  <?php$number = 1234.56;  // english notation (default) $english_format_number = number_format($number); // 1,235  // French notation $nombre_format_francais = number_format($number, 2, ',', ' '); // 1 234,56  $number = 1234.5678;  // english notation without thousands seperator $english_format_number = number_format($number, 2, '.', ''); // 1234.57  ?> strrev()//字符串反转 md5(); md5_file();

asp特有的:
asp中有left(), right() php中无