Help With Strings
Posted: Sun Oct 05, 2008 2:06 am
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
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