Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

569
Views
Call to undefined function str_contains() php

My code works on localhost via APACHE, but when I hosted a website with all the same files and code i get this message: Fatal error: Call to undefined function str_contains() in /storage/ssd3/524/16325524/public_html/static/header.php on line 55
PHP Code where error shows:

<?php
                            $menu = getAllData('meni');
                            global $korisnik;
                            for ($i = 0; $i < count($menu); $i++){
                                if(isset($_SESSION['korisnik'])){
                                    if(str_contains($menu[$i]->naziv, 'login') || str_contains($menu[$i]->naziv, 'reg')){
                                        continue;
                                    }
                                    echo  '<li><a href='.$menu[$i]->putanja.'>'.$menu[$i]->naziv.'</a></li>';
                                }
                                else {
                                    if (str_contains($menu[$i]->naziv, 'profile') || str_contains($menu[$i]->naziv, 'out')) {
                                        continue;
                                    }
                                    echo '<li><a href=' . $menu[$i]->putanja . '>' . $menu[$i]->naziv . '</a></li>';
                                }
                            }
                            ?>
over 4 years ago · Santiago Trujillo
4 answers
Answer question

0

See enabled Apache modules

sudo apachectl -M

Disable 7.4 modules

sudo a2dismod php7.*

Enable php8

sudo a2enmod php8.1
over 4 years ago · Santiago Trujillo Report

0

The docs say str_contains was introduced in PHP 8.0.

over 4 years ago · Santiago Trujillo Report

0

str_contains() was introduced in PHP 8 and is not supported in lower versions.

For lower PHP versions, you can use a workaround with strpos():

if (strpos($haystack, $needle) !== false) {
  // haystack contains needle
}
over 4 years ago · Santiago Trujillo Report

0

The manual page for str_contains says the function was introduced in PHP 8. I suspect your host is on PHP 7 (or possibly lower).

You can define a polyfill for earlier versions (adapted from https://github.com/symfony/polyfill-php80)

if (!function_exists('str_contains')) {
    function str_contains(string $haystack, string $needle): bool
    {
        return '' === $needle || false !== strpos($haystack, $needle);
    }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!