﻿id,summary,reporter,owner,description,type,status,priority,milestone,component,version,severity,resolution,keywords,cc
19347,"Ugly alert: false !== strpos( $which_one_was_needle, $this_one )",nbachiyski,westi,"In WordPress {{{strpos()}}} is used hundreds of times. Very large percentage of those calls are trying to accomplish one of these 3 goals:

 * Check if a string starts with another string
 * Check if a string contains another string
 * Check if a string ends with another string

The code for doing these 3 things is not very readable, ugly, and error-prone:

{{{
0 === strpos( $one_string, $other_string )
false !== strpos( $one_string, $other_string )
strpos( $one_string, $other_string ) == ( strlen( $one_string ) - strlen( $other_string )
}}}

I propose we introduce functions to hide the ugliness and the complexity behind these three common operations:

 * {{{wp_startswith( $haystack, $needle )}}}
 * {{{wp_in( $needle, $haystack )}}}
 * {{{wp_endswith( $haystack, $needle )}}}

The logic of the arguments order is consistent and easy to remember:

''first argument'' '''verb''' ''second argument''.

 * everything starts with a beginning translates to {{{wp_startswith( ""everything"", ""a beginning"" )}}}
 * goat is in  distress translates to {{{wp_in( ""goat"", ""distress"" )}}}
 * movie ends with happy end translates to {{{wp_endswith( ""movie"", ""happy end"" )}}}

These three functions are happily used in GlotPress and WordPress.com.

The implementations are attached.",enhancement,reviewing,normal,Future Release,General,,normal,,has-patch westi-likes 3.5-early,ercoli@… mitcho@… jeremy@… zack@…
