*
* @return integer The position of first occurrence.
*/
- static public function pos($haystack, $needle, $offset, $charset = 'UTF-8')
+ static public function pos($haystack, $needle, $offset = 0,
+ $charset = 'UTF-8')
{
if (Horde_Util::extensionExists('mbstring')) {
$track_errors = ini_set('track_errors', 1);
}
/**
+ * Returns the numeric position of the last occurrence of $needle
+ * in the $haystack string.
+ *
+ * @param string $haystack The string to search through.
+ * @param string $needle The string to search for.
+ * @param integer $offset Allows to specify which character in haystack
+ * to start searching.
+ * @param string $charset The charset to use when searching for the
+ * $needle string.
+ *
+ * @return integer The position of first occurrence.
+ */
+ static public function rpos($haystack, $needle, $offset = 0,
+ $charset = 'UTF-8')
+ {
+ if (Horde_Util::extensionExists('mbstring')) {
+ $track_errors = ini_set('track_errors', 1);
+ $ret = @mb_strrpos($haystack, $needle, $offset, self::_mbstringCharset($charset));
+ ini_set('track_errors', $track_errors);
+ if (!isset($php_errormsg)) {
+ return $ret;
+ }
+ }
+
+ return strrpos($haystack, $needle, $offset);
+ }
+
+ /**
* Returns a string padded to a certain length with another string.
* This method behaves exactly like str_pad() but is multibyte safe.
*
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
<notes>
+* Added Horde_String::rpos().
* Renamed Horde_Array::array_merge_recursive_overwrite() to Horde_Array::replaceRecursive().
+* Added Horde_String::common().
* Added Horde_Domhtml::.
* Removed Horde_Util::assertDriverConfig().
* Removed Horde_Util::bufferOutput().
Horde_String::length('Я могу есть стекло, оно мне не вредит.', 'utf-8'));
}
+ public function testPos()
+ {
+ $this->assertEquals(3, Horde_String::pos('Schöne Neue Welt', 'ö'));
+ $this->assertEquals(7, Horde_String::pos('Schöne Neue Welt', 'N'));
+ $this->assertEquals(6, Horde_String::pos('Schöne Neue Welt', ' '));
+ $this->assertEquals(3, Horde_String::rpos('Schöne Neue Welt', 'ö'));
+ $this->assertEquals(7, Horde_String::rpos('Schöne Neue Welt', 'N'));
+ $this->assertEquals(11, Horde_String::rpos('Schöne Neue Welt', ' '));
+ }
+
public function testPad()
{
/* Simple single byte tests. */