Reply
strripos with PHP4
Old 05-19-2008, 02:30 PM strripos with PHP4
KkillgasmM's Avatar
Ultra Talker

Posts: 352
Name: El Phantasmo
Location: England, north west
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]
__________________
http://www.inspindesign.co.uk
KkillgasmM is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 05-19-2008, 05:58 PM Re: strripos with PHP4
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 953
Name: Jeremy Miller
Location: Reno, NV
Try applying strrpos to the string in lowercase format. The position won't change and you'll have a case-insensitive search.
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-20-2008, 11:53 AM Re: strripos with PHP4
Average Talker

Posts: 28
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, 10:43 PM Re: strripos with PHP4
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 953
Name: Jeremy Miller
Location: Reno, NV
Intriguing Cory. I wonder which is faster: converting to lowercase or reversing the string...
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-21-2008, 07:24 AM Re: strripos with PHP4
Average Talker

Posts: 28
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, 06:01 PM Re: strripos with PHP4
Ultra Talker

Posts: 479
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...
__________________
Free PHP Obfuscator
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to strripos with PHP4
 

Thread Tools

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

vB 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.13648 seconds with 13 queries