Jump to content

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'.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.