0

I have a function that works in PHP v 5.3 and above but wondering what is the best method for doing this with a version below 5.3. My PHP version is 5.2.17

Here is my function for PHP v5.3

if (strstr($file2, '.', true) == strstr($file, '.', true)){
    $imagename = $file2;
}
Teun Zengerink
  • 4,277
  • 5
  • 30
  • 32
user1561466
  • 71
  • 1
  • 3
  • 11

3 Answers3

0

From the manual comments, you could find this:

function rstrstr($haystack,$needle, $start=0) {
   return substr($haystack, $start,strpos($haystack, $needle));
}
xdazz
  • 158,678
  • 38
  • 247
  • 274
0

There is another question with this subject and the solution they found is to create your own strstr function which can be used also in old versions of php.

function my_strstr($haystack, $needle, $before_needle = false) { 
    if (!$before_needle) return strstr($haystack, $needle); 
    else return substr($haystack, 0, strpos($haystack, $needle)); 
} 
Community
  • 1
  • 1
Mihai Matei
  • 24,166
  • 5
  • 32
  • 50
0

Instead of

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

I used the following and it works

if (substr($file2,0,strpos($file2,'.')) == substr($file,0,strpos($file,'.'))){
user1561466
  • 71
  • 1
  • 3
  • 11