String comparison; finding 'like' characters
php
Solution
stripos(), as per the manual only exists in the core of PHP 5 or later. If stripos doesn't exist, that would suggest you're using PHP 4, which is wildly outdated. I suggest you upgrade. If for some insane reason you really can't, you can always force the two strings to lowercase before calling strpos, which would have the same effect:
<?php
// PHP 5.
$pos = stripos( 'www.google.com', 'google.com' );
// PHP 4.
$pos = strpos( strtolower( 'www.google.com' ), strtolower( 'google.com' ) );
That said, there's something more to your code: you're checking `if( stripos( $foo, $bar ) )` which would return 0 if the string `$foo` starts with the string `$bar`. You should check with `if( stripos( $foo, $bar ) !== false )` instead.
On another note: I don't think stripos will help you. You mentioned `www.google.com` and `www.goog.com`, which are two totally different things. The latter is not a substring of the former, and stripos checks for the starting position of a substring, it doesn't do "loose comparison".
If you want "like" and you have the terms in an array, you might want to check out the similar_text() function which will give you an indication of how similar two different strings are. As an example:
<?php
$similarity = 0;
similar_text( 'www.goog.com', 'www.google.com', $similarity );
var_dump( $similarity );
The above code would set `$similarity` to `float(92.307692307692)`, which is the similarity of the two strings in percentages. You can decide the threshold for the similarity yourself, naturally.
Problem
I am doing a quick duplicate check on a form. When comparing two strings, I was trying something like this: ``` if (stripos($_SESSION['website'], $f['website'])) ``` I am getting this error: ``` Fatal error: Call to undefined function: stripos() in... ``` I do not want it to be an exact match, basically if the `$_SESSION['website']` is www.google.com, I'd want `stripos` to return `true` if `$f['website]` is www.goog.com Am I doing something wrong, or is there a better way to do this? edit: I was doing some testing, and noticed if my `$_SESSION['website']` variable contains `www` and `.com`. As does my `$f['website]` variable. shouldn't `strpos` return that as true?