ASP InStr 与 PHP strpos
ASP InStr vs PHP strpos
我有一些代码要从 ASP 转换为 PHP 我遇到了
InStr。所以我查找了 php 等价物,它是 strpos。我测试了两者,当我这样做时
InStr("E-","E")
我得到的结果是 1,但是 strpos("E-","E")
我得到的结果是 0 我卡住了关于如何在 php
中获得 InStr 的类似结果
您可以像这样创建一个 InStr 函数:
function InStr($haystack, $needle, $offset = 0)
{
$position = strpos($haystack, $needle, $offset);
return ($position !== false) ? $position += 1 : 0;
}
我有一些代码要从 ASP 转换为 PHP 我遇到了
InStr。所以我查找了 php 等价物,它是 strpos。我测试了两者,当我这样做时
InStr("E-","E")
我得到的结果是 1,但是 strpos("E-","E")
我得到的结果是 0 我卡住了关于如何在 php
您可以像这样创建一个 InStr 函数:
function InStr($haystack, $needle, $offset = 0)
{
$position = strpos($haystack, $needle, $offset);
return ($position !== false) ? $position += 1 : 0;
}