Jump to: navigation, search

Php strstr

From w3cyberlearnings

Contents

PHP function strstr

This function searches for the first occurences of a given string.

Syntax strstr

  • string: string to be used for search
  • search: list of string to search for, if ASCII number will force to search the ASCII value.
  • before_handler (option): if set to true return the part of the haystack before the first occurences
strstr(string, search,before_handler)

Example 1

  • Search: @
<?php

$email = "[email protected]";
$domain = strstr($email, '@');
echo $domain;
?>

Output

@w3cyberlearnings.com

Example 2

  • strstr is case sensitive match.
  • Not match the 'All' but match the 'all'.
<?php

$sentence ='All Girl will kick all type of balls';
$match = strstr($sentence,'all');
echo $match;
?>

Output

all type of balls

Example 3

  • Match using the ASCII number.
  • The ASCII number convert to the ASCII value.
  • 64=@
<?php

$email = "[email protected]";
$domain = strstr($email, 64);
echo $domain;
?>

Output

@w3cyberlearnings.com

Example 4

  • assign: before_handler option to true thus return before the first occurences.
<?php

$email = "[email protected]";
$domain = strstr($email, 64,true);
echo $domain;
?>

Output

bob200

Related Functions


Navigation
Web
SQL
MISC
References