Coder Social home page Coder Social logo

emoji-php's Introduction

Emoji Detecting and Processing

Unicode version: 15.0.

Installation

Install this library using the Composer require command:

composer require maximal/emoji '^1.0'

or add the package name to the require section of your composer.json file:

"require": {
	"maximal/emoji": "^1.0"
}

and then run:

composer update

Then include Composer autoload anywhere in your code:

require_once __DIR__ . '/vendor/autoload.php';

Usage

use Maximal\Emoji\Detector;

// Whether the given string contains emoji characters
$isEmojiFound = Detector::containsEmoji($string);
// 'test' -> false
// 'test πŸ‘' -> true

// Whether the given string consists of emoji characters only
$isEmojiOnly = Detector::onlyEmoji($string);
// 'test πŸ‘' -> false
// 'πŸ‘πŸ˜˜' -> true

// String without any emoji character
$stringWithoutEmoji = Detector::removeEmoji($string);
// 'test πŸ‘' -> 'test '
// 'πŸ‘πŸ˜˜' -> ''

// All emojis of the string
$allEmojis = Detector::allEmojis($string);
// 'test πŸ‘' -> ['πŸ‘']
// 'πŸ‘πŸ˜˜' -> ['πŸ‘', '😘']

// Starting emojis of the string
$startingEmojis = Detector::startingEmojis($string);
// 'πŸ‘πŸ˜˜ test' -> ['πŸ‘', '😘']
// 'test πŸ‘' -> []

containsEmoji($string): bool

Detects whether the given string contains one or more emoji characters.

onlyEmoji($string, $ignoreWhitespace = true): bool

Detects whether the given string consists of emoji characters only.

This method ignores any spaces, tabs and other whitespace characters (\s). Pass false to the second parameter for not ignoring whitespace characters.

removeEmoji($string): string

Returns the given string with all emoji characters removed.

allEmojis($string): array

Returns an array of all emojis of the input string.

startingEmojis($string, $ignoreWhitespace = true): array

Returns an array of starting emojis of the input string.

This method ignores any spaces, tabs and other whitespace characters (\s). Pass false to the second parameter for not ignoring whitespace characters.

Tests

Run simple tests:

php test/tests.php

Expected output:

Tests total:  119
        run:  119
  succeeded:  119
     failed:  0

Contact the author

emoji-php's People

Contributors

maximal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

am0n666

emoji-php's Issues

Support for PHP 8.0 and 8.1

 Updating dependencies
 Your requirements could not be resolved to an installable set of packages.
 
   Problem 1
     - Root composer.json requires maximal/emoji ^1.0 -> satisfiable by maximal/emoji[v1.0, v1.1, v1.2].
     - maximal/emoji[v1.0, ..., v1.2] require php ^7.0 -> your php version (8.0.16; overridden via config.platform, same as actual) does not satisfy that requirement.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.