PHP

PHP Menu

PHP

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

Definition

The strstr() function searches for the first occurrence of a string inside another string.

Syntax

strstr(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 strstr("Welcome to PHP!", "to"); echo "<br>"; echo strstr("Welcome to PHP!", "to", true);

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods