93 of 410 menu

The strchr Function

The strchr function finds the first occurrence of a substring in a string and returns the part of the string starting from that location to the end of the string. If the second parameter consists of more than one character, only the first character is used.

Syntax

strchr(string $haystack, string $needle, bool $before_needle = false): string|false

Example . Usage

Let's extract the page address without the domain name from the URL (will return the substring, starting from the first /, to the end of the string)

<?php echo strchr('site.ru/dir1/dir2/page.html', '/'); ?>

Code execution result:

'/dir1/dir2/page.html'

See Also

  • the strstr function,
    which finds the first occurrence of a substring
  • the strrchr function,
    which finds the last occurrence of a character
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline