PHP strchr() Function

PHP strchr() Function

The strchr() function in PHP searches for the first occurrence of the specified string inside another string. It is a binary-safe case -sensitive function and is the alias of strstr() function.

Syntax

strstr ( string $haystack , mixed $needle [, bool $before_needle] )

Parameter

haystack(required)- This parameter represents the input string.

needle(required)- This parameter signifies the string to search for. If it is a number, it will search for the character matching the ASCII value of the number.

before_needle(optional)- This parameter takes a boolean and its value default is "false". If it is set to "true", it returns the part of the string before the first occurrence of the search parameter.

Return

This function returns the portion of the string, or FALSE if the needle is not found.

Example 1

   

Output

The strchr() function returns World  

Example 2

 

Output

o PHP!

Example 3

 

Output

Hello 

Related Topics

PHP strripos() Function

PHP strripos() Function The strripos() function in PHP finds the position of the last occurrence of a substring in the specified string. It is a case-insensitive and binary-safe function. Syntax strripos ( string $haystack , mixed $needle [, int $offset ] ) Parameter haystack(required)- This parameter signifies the...

1 minute read.

PHP str_split() Function

PHP str_split() Function The str_split() function in PHP splits a string into an array. String str_split ( string $string [, int $split_length = 1 ] ) Parameter string(required)- This parameter represents the input string. split_length(optional)- This parameter signifies the maximum length of the chunk. The default value is 1. Return This function...

2 minutes read.

PHP ucfirst() Function

PHP ucfirst() Function The ucfirst() function in PHP converts the first character of the specified string to uppercase. Syntax ucfirst ( string $str ) Parameter str(required)- This parameter represents the input string. Return This function returns a string with the first character of the specified string capitalized if that...

1 minute read.

PHP shuffle() Function

PHP shuffle() Function The shuffle() function in PHP shuffles an array in a random array. Syntax shuffle ( array &$array )  Parameter array(required)- This parameter represents the input array.  Return This parameter returns a Boolean value TRUE on success or FALSE on failure. Example 1 Output Original Array: Array ...

1 minute read.

PHP is_array() Function

The is_array() Function in PHP is used to  find whether a variable is an array or not. It returns a Boolean value true if the parameter var is an array else it returns...

1 minute read.

PHP array_intersect_key() function

The array_intersect_key () function in PHP is used to compute the intersection of arrays using keys for comparison. It returns an array containing all the entries from array1 which have keys that are present in...

1 minute read.

PHP ksort() Function

PHP ksort() Function The ksort() function in PHP sorts an array by key while maintaining the keys. Syntax ksort(array & $array[,int $sort_flags = SORT_REGULAR] ) Parameter array(required)- This parameter represents the input array. sort_flags(optional)- This parameter is...

2 minutes read.

PHP sprintf() Function

PHP sprintf() Function The sprintf() function in PHP is used to write a formatted string to a variable and returns a formatted string. PHP 4 and above versions support the sprintf() function. The related functions are...

8 minutes read.

PHP array_udiff_assoc() Function

PHP array_udiff_assoc() Function The array_udiff_assoc () function in PHP computes the difference between the specified arrays with additional index check and compares the data by a callback function. It returns all the values from array1 that are not...

1 minute read.

PHP uasort() Function

PHP uasort() Function The uasort() function in PHP sorts an array with a user-defined comparison function and maintains the index association. Syntax uasort ( array &$array , callable $value_compare_func ) Parameter array(required)- This parameter represents the input array. value_compare_func(required)- This parameter represents a string that describe a...

1 minute read.

PHP array_values() Function

PHP array_values() Function The array_values () function in PHP returns all the values from the array and indexes the array numerically. Syntax array_values ( array $array ) Parameter array(required)- This array represents the input array. Return This function returns an indexed array of values. Example 1 Output Input Array: Array ...

1 minute read.

PHP array_diff_uassoc() Function

PHP array_diff_uassoc() Function The array_diff_uassoc () Function in PHP is used to compare the keys and values of two (or more) arrays and returns the differences (an array containing the entries from the first array that...

1 minute read.

PHP array_reduce() Function

PHP array_reduce() Function The array_reduce() function in PHP reduces the array to a single value using by applying a callback function to the elements of the array. Syntax array_reduce ( array $array , callable $callback [, mixed $initial = NULL ] ) Parameter array(required)- This parameter represents the input array. callback (required)- This...

1 minute read.

PHP Constant

PHP constant is an identifier(name) for a simple value. The value does not change during the script. It starts with a letter or underscore not $ sign. The define()function is...

1 minute read.

PHP chunk_split() Function

PHP chunk_split() Function The chunk_split() function in PHP splits a string into a series of smaller parts. Syntax chunk_split(string,length,end) Parameter string(required)- It specifies the string to split. length(optional)- This parameter represents a number that defines the...

1 minute read.

PHP array_slice() Function

PHP array_slice() Function The array_slice() function in PHP is used to extract a slice of the array. It returns the sequence of elements from the array as specified by the offset and length parameters. Syntax array_slice ( array $array , int $offset [, int $length = NULL [, bool $preserve_keys = FALSE ]] ) Parameter array(required)- This array represents the...

2 minutes read.

PHP stristr() Function

PHP stristr() Function The stristr() function in PHP finds the first occurrence of a string and returns the matched substring. It is a case-insensitive function. Syntax stristr ( string $haystack , mixed $needle [, bool $before_needle ] ) Parameter haystack(required)- This parameter represents the input string. needle(required)- This parameter...

2 minutes read.

PHP printf() Function

PHP printf() Function The printf() function in PHP outputs a formatted string. The related functions of printf() function are as follows: sprintf()vprintf()vsprintf()fprintf()vfprintf() Syntax printf ( string $format [, mixed $... ] )  Parameter format(required)- This parameter formats the string which is composed of zero or...

1 minute read.

PHP strlen() Function

PHP strlen() Function The strlen() function in PHP is used to return the length of the specified string. Syntax strlen ( string $string ) Parameter string(required)- This parameter represents the string which is measured for length. Return This function returns the length of the string on success or returns 0 if the specified...

1 minute read.

PHP Multidimensional Array

An array of arrays is called multidimensional array. It is used to store the data in a tabular form. It is represented in the form of matrix (row*column). Example: We can store...

2 minutes read.