Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 05-19-2008, 03:30 PM strripos with PHP4
pealo86's Avatar
Super Spam Talker

Posts: 849
Name: Matt Pealing
Location: England, north west
Trades: 0
My client only has PHP4 installed on his hosting account. And I need to use the function [or a substitute] in order to find the last occurance of a character in a string.

Does anyonoe know of a solution to this? As strripos is not part of PHP4 [also isn't recognised by Dreamweaver which is a bit strange]
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
 
Register now for full access!
Old 05-19-2008, 06:58 PM Re: strripos with PHP4
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Try applying strrpos to the string in lowercase format. The position won't change and you'll have a case-insensitive search.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-20-2008, 12:53 PM Re: strripos with PHP4
Average Talker

Posts: 28
Trades: 0
I recently ran into something where I needed to use a string to search, in PHP 4, instead of character. Basically, I just reversed the string, then did strpos. Here's a snippet:

//PHP 4 doesn't support multiple characters in strrpos(), so we must find positions based on strrev()
trim(strip_tags(substr($line, (strlen($line) - strpos(strrev($line), strrev("<TD >"))))))
Cory Dee is offline
Reply With Quote
View Public Profile
 
Old 05-20-2008, 11:43 PM Re: strripos with PHP4
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Intriguing Cory. I wonder which is faster: converting to lowercase or reversing the string...
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-21-2008, 08:24 AM Re: strripos with PHP4
Average Talker

Posts: 28
Trades: 0
For my circumstance, it wasn't an issue of case sensitivity, it was the fact that strrpos() acts like strrchar(), and does not handle multiple characters.

Now that I'm re-reading, I'm not sure that the original poster was running into that circumstance...
Cory Dee is offline
Reply With Quote
View Public Profile
 
Old 05-21-2008, 07:01 PM Re: strripos with PHP4
Ultra Talker

Posts: 483
Trades: 0
Whenever I'm looking for a PHP4 implementation of a PHP5 function, I head straight to php.net...

The comments at the bottom of http://php.net/strripos , for example, have this little gem:
PHP Code:
if(!function_exists("stripos")){
    function 
stripos(  $str$needle$offset 0  ){
        return 
strpos(  strtolower$str ), strtolower$needle ), $offset  );
    }
/* endfunction stripos */
}/* endfunction exists stripos */

if(!function_exists("strripos")){
    function 
strripos(  $haystack$needle$offset 0  ) {
        if(  !
is_string$needle )  )$needle chr(  intval$needle )  );
        if(  
$offset 0  ){
            
$temp_cut strrev(  substr$haystack0abs($offset) )  );
        }
        else{
            
$temp_cut strrev(    substr(   $haystack0max(  ( strlen($haystack) - $offset ), 0  )   )    );
        }
        if(   (  
$found stripos$temp_cutstrrev($needle) )  ) === FALSE   )return FALSE;
        
$pos = (   strlen(  $haystack  ) - (  $found $offset strlen$needle )  )   );
        return 
$pos;
    }
/* endfunction strripos */
}/* endfunction exists strripos */ 
Hopefully that helps you...
__________________

Please login or register to view this content. Registration is FREE
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to strripos with PHP4
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23446 seconds with 12 queries