PHP » PYTHON |
login |
register |
about
|
# returns -1 when not found: pos = haystack.find(needle) pos = haystack.find(needle, offset) # raises ValueError when not found: pos = haystack.index(needle) pos = haystack.index(needle, offset) To simply test if a substring is in a string, use: needle in haystack strpos(haystack, needle) !== FALSE
strpos(PHP 4, PHP 5) strpos — Find position of first occurrence of a string DescriptionReturns the numeric position of the first occurrence of needle in the haystack string. Unlike the strrpos() before PHP 5, this function can take a full string as the needle parameter and the entire string will be used. Parameters
Return ValuesReturns the position as an integer. If needle is not found, strpos() will return boolean FALSE. Warning
This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". Please read the section on Booleans for more information. Use the === operator for testing the return value of this function. Examples
Example #1 Using ===
<?php
Example #2 Using !==
<?php
Example #3 Using an offset
<?php
Notes
See Also
|
more
Recently updated
more
Most requested
more
Last requests
|