Quick actions

cmd+k|ctrl+k

Navigation

Languages

PHP strpos fuckery

Snippet info

Language

Php

Visibility

public

Author

atomicptr

Created

2021-07-29T13:19:29.111615Z

Updated

2021-07-29T13:19:29.111615Z

<?php

$string = "YOLOTest";

// bad, should print
if (strpos($string, "YOLO") >= 0) {
    echo "YOLO!!!\n";
}

// bad, should not print
if (strpos($string, "SWAG") >= 0) {
    echo "SWAG!!!\n";
}

// good, should print
$res = strpos($string, "YOLO");
if ($res !== false && $res >= 0) {
    echo "YOLO!!!\n";
}

// good, should not print
$res = strpos($string, "SWAG");
if ($res !== false && $res >= 0) {
    echo "SWAG!!!\n";
}
INFO