PluginProbe
RSVP and Event Management / 2.7.5
RSVP and Event Management v2.7.5
trunk 0.5.0 0.6.0 0.7.0 0.8.0 0.9.0 0.9.5 1.0.0 1.1.0 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.5.0 1.6.0 1.6.1 1.6.2 1.6.5 1.7.0 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 All 136 releases
rsvp / external-libs / spout / src / Spout / Common / Helper / StringHelper.php

StringHelper.php in RSVP and Event Management 2.7.5, at external-libs/spout/src/Spout/Common/Helper/StringHelper.php

68 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Box\Spout\Common\Helper;
4
5 /**
6 * Class StringHelper
7 * This class provides helper functions to work with strings and multibyte strings.
8 *
9 * @codeCoverageIgnore
10 *
11 * @package Box\Spout\Common\Helper
12 */
13 class StringHelper {
14
15 /** @var bool Whether the mbstring extension is loaded */
16 protected $hasMbstringSupport;
17
18 /**
19 *
20 */
21 public function __construct() {
22 $this->hasMbstringSupport = extension_loaded( 'mbstring' );
23 }
24
25 /**
26 * Returns the length of the given string.
27 * It uses the multi-bytes function is available.
28 * @see strlen
29 * @see mb_strlen
30 *
31 * @param string $string
32 * @return int
33 */
34 public function getStringLength( $string ) {
35 return $this->hasMbstringSupport ? mb_strlen( $string ) : strlen( $string );
36 }
37
38 /**
39 * Returns the position of the first occurrence of the given character/substring within the given string.
40 * It uses the multi-bytes function is available.
41 * @see strpos
42 * @see mb_strpos
43 *
44 * @param string $char Needle
45 * @param string $string Haystack
46 * @return int Char/substring's first occurrence position within the string if found (starts at 0) or -1 if not found
47 */
48 public function getCharFirstOccurrencePosition( $char, $string ) {
49 $position = $this->hasMbstringSupport ? mb_strpos( $string, $char ) : strpos( $string, $char );
50 return ( $position !== false ) ? $position : -1;
51 }
52
53 /**
54 * Returns the position of the last occurrence of the given character/substring within the given string.
55 * It uses the multi-bytes function is available.
56 * @see strrpos
57 * @see mb_strrpos
58 *
59 * @param string $char Needle
60 * @param string $string Haystack
61 * @return int Char/substring's last occurrence position within the string if found (starts at 0) or -1 if not found
62 */
63 public function getCharLastOccurrencePosition( $char, $string ) {
64 $position = $this->hasMbstringSupport ? mb_strrpos( $string, $char ) : strrpos( $string, $char );
65 return ( $position !== false ) ? $position : -1;
66 }
67 }
68