View Single Post
  #55 (permalink)  
Old 11-08-2007, 09:54 PM
venkat_charya venkat_charya is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 118
venkat_charya is on a distinguished road
Thumbs up Re: string functions and manipulations in php

Hi,

strripos() vs strrpos()

strripos -- Find position of last occurrence of a case-insensitive string in a string
strrpos -- Find position of last occurrence of a char in a string

PHP Code:
<?php
/*-----------STRRIPOS------------------------*/
$haystack 'ababcd';
$needle   'aB';

$pos      strripos($haystack$needle);

if (
$pos === false) {
    echo 
"Sorry, we did not find ($needle) in ($haystack)";
} else {
    echo 
"Congratulations!\n";
    echo 
"We found the last ($needle) in ($haystack) at position ($pos)";
}
/*-------------------------------------------*/
/*-----------STRRPOS------------------------*/
// in PHP 4.0b3 and newer:
$pos strrpos($mystring"b");
if (
$pos === false) { // note: three equal signs
    // not found...
}

// in versions older than 4.0b3:
$pos strrpos($mystring"b");
if (
is_bool($pos) && !$pos) {
    
// not found...
}
/*-------------------------------------------*/
?>
Thanks
__________________
K K Venkata Charya
Success is easy to get but difficult to retain
Reply With Quote