Return Value:Returns the portion of string, or FALSE if the string to search for is not found.Changelog:Since PHP 7.3.0, passing an integer as search parameter has been deprecated.Version:PHP 4+
Syntax
The basic syntax of the strstr() function is given with:
strstr(string, search, before_search);
The following example shows the strstr() function in action.
Tip: If you simply want to find out if a particular substring occurs within a string or not, use the faster and less memory intensive function strpos() instead.
Parameters
The strstr() function accepts the following parameters.
ParameterDescriptionstringRequired. Specifies the string to search.searchRequired. Specifies the string to search for.before_searchOptional. If set to true, it returns the part of the string before the first occurrence of the search string. Default value is 0 which returns all of the string after the first occurrence of the search string (including search string itself).
- Home
- PHP Home
- PHP function Reference
- ▼String
- addcslashes
- addslashes
- bin2hex
- chop
- chr
- chunk_split
- convert_cyr_string
- convert_uudecode
- convert_uuencode
- count_chars
- crc32
- crypt
- explode
- fprintf
- get_html_ translation_ table
- hebrev
- html_entity_decode
- htmlentities
- htmlspecialchars_ decode
- htmlspecialchars
- implode
- join
- ltrim
- md5_file
- md5
- metaphone
- nl2br
- number_format
- ord
- parse_str
- printf
- quoted_printable_ decode
- quotemeta
- rtrim
- sha1_file
- sha1
- similar_text
- sprintf
- sscanf
- str_repeat
- str_shuffle
- str_split
- str_word_count
- strcasecmp
- strchr
- strcmp
- strcoll
- strcspn
- strip_tags
- stripcslashes
- stripos
- strlen
- strnatcmp
- strncasecmp
- strncmp
- strrchr
- strrev
- strripos
- strrpos
- strspn
- strstr
- strtolower
- strtoupper
- strtr
- substr_compare
- substr_count
- substr_replace
- substr
- trim
- ucfirst
- ucwords
- vfprintf
- vprintf
- wordwrap
The strstr() function is used to get the first occurrence of a string inside another string. This function is case-sensitive. Version: (PHP 4 and above) Syntax: Parameters: NameDescriptionRequired / *Mixed: Mixed indicates that a parameter may accept multiple (but not necessarily all) types. Return value:Description
OptionalTypestring_nameThe input string.RequiredStringsearch_stringThe string to search for.RequiredMixed*before_searchReturns the part of the string_name before the first occurrence of the search_string when true.OptionalBoolean
The portion of the string, or false if search_string is not found.
Value Type: String.
Pictorial Presentation
Example:
<?php $string1="W3RESOURCE.COM"; $newstring=strstr($string1,"."); echo $newstring; ?>Output:
.COMView the example in the browser
See also
PHP Function Reference
Previous: strspn
Next: strtolower
Follow us on Facebook and Twitter for latest update.
PHP: Tips of the Day
PHP - Using braces with dynamic variable names in PHP
Wrap them in {}:
${"file" . $i} = file($filelist[$i]);Working Example
Using ${} is a way to create dynamic variables, simple example:
${'a' . 'b'} = 'hello there'; echo $ab; // hello thereRef : //bit.ly/2XPoYGJ
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises