Jump to content

[SOLVED] String Matching


profitweaver

Recommended Posts

Hi,

 

I am a novice at this.

 

I am trying to find an instance of a string within another string. I have found several functions that do this. I have tested the functions and they seem to work ok, so I know the syntax is correct.

 

However, I am passing a variable containing one string to this function in another file. The string is being passed ok, but the function will not correctly tell me that one string contains another when I know that it does.

 

For example.

 

<?php

$pos = stristr("<?=$cat?>", "<?=$choosecat?>");

  if ($pos === false)

    echo "The string '$choosecat' was not found in the string '$cat'";

  else {

    echo "The string '$choosecat' was found in the string '$cat'";

    echo " and exists at position $pos";

}

?>

 

always returns false.

 

Can anyone give me a clue why this isn't working please?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/127095-solved-string-matching/
Share on other sites

Of course that always returns false.

 

It's like asking, "Is the word 'judge' inside the word 'judgment'" and the answer is no, because there is no 'e' after the the 'g' in judgment.

 

However, if you ask "Is the 'ball' inside the word 'ballpark', then the answer would be yes, because the word 'ball' exists in its entirety in 'ballpark'.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.