stripos( $haystack, $needle )
- Source
wp-includes/class-pop3.php:662
Finds where a substring first occurs inside another string while ignoring letter case, exactly like PHP's own stripos(). WordPress only defines its own version of this function inside a function_exists() guard, so on every supported PHP build your code actually calls PHP's native stripos(), offset argument and all, not the two-parameter version shown in core. The core copy is built by combining strpos() with stristr(), which shapes what it returns when nothing matches. Reach for strpos() instead when case should matter, or mb_stripos() when the haystack may contain multibyte characters.
Compatibility
- WordPress
- core
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$haystack$needle
Code examples
Every example is editable and runs in a real WordPress booted in your browser by WordPress Playground. Press Run, then edit the code: clicking away re-runs it. Nothing is sent anywhere until you do.
Search post titles case-insensitively for a keyword
Loop over the five baseline posts and flag any title that contains a word regardless of how it's capitalized.
$posts = get_posts( array( 'numberposts' => 5, 'orderby' => 'ID', 'order' => 'ASC' ) );
foreach ( $posts as $post ) {
$found = stripos( $post->post_title, 'HELLO' ) !== false;
printf( '%s: %s<br>', esc_html( $post->post_title ), $found ? 'matches keyword' : 'no match' );
}Post 1's title "Hello world!" matches even though the search term is written in all caps.
Detect a mail transport by name regardless of case
Check a sendmail-style path for the string "qmail" the same way core's mail classes sniff for it.
$sendmail_path = '/usr/sbin/Qmail-inject';
if ( stripos( $sendmail_path, 'qmail' ) !== false ) {
echo esc_html( 'Mail transport looks like qmail: ' . $sendmail_path );
} else {
echo esc_html( 'Mail transport is not qmail-based.' );
}Common problems and fixes · 3
- Why does my if(stripos(...)) check fail even though the match is right at the start of the string?
- Why can't I pass a third offset argument to stripos()?
- Why would this function return 0 instead of false when the search term genuinely isn't in the string?
Why does my if(stripos(...)) check fail even though the match is right at the start of the string?
Why can't I pass a third offset argument to stripos()?
Why would this function return 0 instead of false when the search term genuinely isn't in the string?
Alternatives and related functions
strpos- When the comparison must be case-sensitive, since strpos() will not match "Hello" against a search for "hello".
stristr- When you need the matched substring itself rather than its numeric position.
mb_stripos- When the haystack or needle contains multibyte characters and byte-based position counting would be wrong.
preg_match- When the search is more than a plain substring, such as matching a pattern with the case-insensitive 'i' modifier.
Performance profile
How much work a call to stripos() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 8
- Plugin surface
- None
- Called by
- 41
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 8.
Nothing here hands control to plugin code.
41 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost stripos() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 8 | stristr() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 8 | 8 | 0 | |
| 8.5 | 8 | 8 | 0 | |
| 8.4 | 8 | 8 | 0 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 11 | 11 | 0 | |
| 8.2 | 11 | 11 | 0 | |
| 8.1 | 11 | 11 | 0 | |
| 7.4 | 11 | 11 | 0 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Used by · 41
- Autoload::load()Autoloader.
- PHPMailer::DKIM_Add()Create the DKIM header and body in a new message header.
- PHPMailer::createBody()
- PHPMailer::isQmail()
- PHPMailer::isSendmail()
- PHPMailer::preSend()Prepare a message for sending.
- POP3::is_ok()
- Parser::prepareHeaders()Prepare headers (take care of proxies headers)
- Request::getBody()Gets the request body.
- Requests::request()Main interface for HTTP requests
- SMTP::get_lines()Read the SMTP server's response.
- WP_Customize_Nav_Menus::search_available_items_query()Performs post queries for available-item searching.
Show all 41
- WP_Filesystem_Base::find_folder()Locates a folder on the remote filesystem.
- WP_Filesystem_FTPext::parselisting()Parses an individual entry from the FTP LIST command output.
- WP_HTML_Tag_Processor::set_modifiable_text()Sets the modifiable text for the matched token, if matched.
- WP_Http_Cookie::test()Confirms that it's OK to send this cookie to the URL checked against.
- WP_Http_Encoding::should_decode()Whether the content be decoded based on the headers.
- WP_Icons_Registry::get_registered_icons()Retrieves all registered icons.
- WP_MS_Themes_List_Table::_search_callback()Filters a theme by the search term.
- WP_Plugins_List_Table::_search_callback()Callback to filter plugins by a search term.
- WP_REST_Post_Format_Search_Handler::search_items()Searches the post formats for a given search request.
- WP_Themes_List_Table::search_theme()
- WP_Token_Map::contains()Indicates if a given word is a lookup key in the map.
- WP_Token_Map::read_token()If the text starting at a given offset is a lookup key in the map, return the corresponding transformation from the map, else `false`.
- WP_oEmbed::discover()Attempts to discover link tags at the given URL for an oEmbed provider.
- _WP_Editors::editor()Outputs the HTML for a single instance of the editor.
- add_query_arg()Retrieves a modified URL query string.
- esc_url()Checks and cleans a URL.
- is_login()Determines whether the current request is for the login screen.
- media_buttons()Adds the media button to the editor.
- ms_load_current_site_and_network()Identifies the network and site of a requested domain and path and populates the corresponding network and site global objects as part of the multisite bootstrap process.
- render_block_core_image()Renders the `core/image` block on the server, adding a data-id attribute to the element if core/gallery has added on pre-render.
- trackback_rdf()Generates and displays the RDF for the trackback information of current post.
- wp_add_inline_script()Adds extra code to a registered script.
- wp_add_inline_style()Adds extra CSS styles to a registered stylesheet.
- wp_ajax_wp_compression_test()Handles compression testing via AJAX.
- wp_mail()Sends an email, similar to PHP's mail function.
- wp_map_nav_menu_locations()Maps nav menu locations according to assignments in previously active theme.
- wp_map_sidebars_widgets()Compares a list of sidebars with their widgets against an allowed list.
- wp_opcache_invalidate()Attempts to clear the opcode cache for an individual PHP file.
- wp_targeted_link_rel()Adds `rel="noopener"` to all HTML A elements that have a target.
Source code
function stripos($haystack, $needle){ return strpos($haystack, stristr( $haystack, $needle )); }Changelog
Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-pop3.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.