PHP

PHP Menu

PHP

strchr() Function - Definition, Syntax, Parameters, Examples

Definition

The strchr() function searches for the first occurrence of a string inside another string. This function is an alias of the strstr() function.

Syntax

strchr(string, search, before_search)

Parameters

Parameter Description
string Required. Specifies the string to search.
search Required. Specifies the string to search for. If this parameter is a number, it will search for the character matching the ASCII value of the number.
before_search Optional. A boolean value whose default is "false". If set to "true", it returns the part of the string before the first occurrence of the search parameter.

Example

<?php
echo strchr("Welcome to PHP!", "PHP");

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods