Oihana PHP Arango

findFirst.php

Table of Contents

Functions

findFirst()  : string
Return the position of the first occurrence of a substring in a string.

Functions

findFirst()

Return the position of the first occurrence of a substring in a string.

findFirst(string $value, string $search, int|null $start, int|null $end) : string

This helper wraps the ArangoDB AQL function FIND_FIRST(text, search, start, end) which returns the position of the first occurrence of the search string within the text string. Positions start at 0. You can optionally limit the search to a subset of the text using start and end parameters.

Example AQL usage:

FIND_FIRST("hello world", "world")        // returns 6
FIND_FIRST("hello world", "o")            // returns 4
FIND_FIRST("hello world", "x")            // returns -1 (not found)
FIND_FIRST("hello world", "o", 5)         // returns 7 (search from position 5)
Parameters
$value : string

The text to search in (haystack).

$search : string

The substring to search for (needle).

$start : int|null

Optional start position to limit search (default: 0).

$end : int|null

Optional end position to limit search (default: end of string).

Tags
example
use function oihana\arango\db\functions\strings\findFirst;

$expr = findFirst('doc.text', '"world"', 0, null);
// Produces: 'FIND_FIRST(doc.text, "world", 0)'
see
https://docs.arangodb.com/stable/aql/functions/string/#find_first
findLast()

For finding the last occurrence.

contains()

For checking if string contains substring.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results