0

我有一个在 PHP v 5.3 及更高版本中工作的函数,但想知道使用低于 5.3 的版本执行此操作的最佳方法是什么。我的 PHP 版本是 5.2.17

这是我的 PHP v5.3 函数

if (strstr($file2, '.', true) == strstr($file, '.', true)){
    $imagename = $file2;
}
4

3 回答 3

0

从手册注释中,您可以找到以下内容:

function rstrstr($haystack,$needle, $start=0) {
   return substr($haystack, $start,strpos($haystack, $needle));
}
于 2012-08-02T07:51:50.573 回答
0

这个主题还有另一个问题,他们找到的解决方案是创建自己的 strstr 函数,该函数也可以在旧版本的 php 中使用。

function my_strstr($haystack, $needle, $before_needle = false) { 
    if (!$before_needle) return strstr($haystack, $needle); 
    else return substr($haystack, 0, strpos($haystack, $needle)); 
} 
于 2012-08-02T08:02:03.520 回答
0

代替

if (strstr($file2, '.', true) == strstr($file, '.', true)){

我使用了以下,它的工作原理

if (substr($file2,0,strpos($file2,'.')) == substr($file,0,strpos($file,'.'))){
于 2012-08-02T08:18:59.963 回答