WordPress.org

Make WordPress Core

Ticket #19347: string-helpers.php

File string-helpers.php, 752 bytes (added by nbachiyski, 2 years ago)
Line 
1<?php
2/**
3 * Convenient functions to make work with strings easier
4 *
5 * @package WordPress
6 **/
7
8/**
9 * Checks if $haystack starts with $needle
10 *
11 * @param string $haystack
12 * @param string $needle
13 * @return bool
14 */
15function wp_startswith( $haystack, $needle ) {
16        return 0 === strpos( $haystack, $needle );
17}
18
19/**
20 * Checks if $haystack ends with $needle
21 *
22 * @param string $haystack
23 * @param string $needle
24 * @return bool
25 */
26function wp_endswith( $haystack, $needle ) {
27        return $needle === substr( $haystack, -strlen( $needle ) );
28}
29
30/**
31 * Checks if $needle is in $haystack
32 *
33 * @param string $needle
34 * @param string $haystack
35 * @return bool
36 */
37function wp_in( $needle, $haystack ) {
38        return false !== strpos( $haystack, $needle );
39}
40