strpos always returns 0 in this rule

1

I do not understand the reason why the following rule returns to me in this case the value 0. The code in PHP is this:

$contador = (strpos($posts[0]['Codigo_juego'],$usuario_color['siguiendo_juegos']) !== FALSE) ? 1 : 0;

What results in this:

$contador = (strpos("c3kldkzbhncz","bzf7k34wnwc2;c3kldkzbhncz;") !== FALSE) ? 1 : 0; 
echo $contador; //me devuelve siempre 0;

The string I'm looking for is inside the string, I should return the value 1, but it returns 0.

    
asked by JetLagFox 03.03.2018 в 01:10
source

2 answers

4

The error is that the second parameter must be contained in the first one, as you are showing in your code so that it returns the position it should be in this way

$contador = (strpos("bzf7k34wnwc2;c3kldkzbhncz;", "c3kldkzbhncz") !== FALSE) ? 1 : 0;

here is the documentation of the function strpos

link

    
answered by 03.03.2018 / 01:21
source
1

here I pass the script and functional only so that checks by fas that was what happened to yours greetings

$name = "dfgdgf;Paz;Lopez;";


$resultado = (strpos($name, "Alfredo") !== FALSE) ? 1 : 0;

echo $resultado; //da 0

the next one gives one because if there is a match

<?php

$name = "Alfredo;Paz;Lopez;";


$resultado = (strpos($name, "Alfredo") !== FALSE) ? 1 : 0;

echo $resultado;
    
answered by 03.03.2018 в 01:26