...

View Full Version : substr_compare ><=



zeee
12-31-2005, 02:51 AM
I want to copare $a, $b and make an echo result based on comparison result.

I tried something lik this, but itsn't not working, need a correction here.

<?
$a = abcde;
$b = BC;
if (substr_compare($a, $b, 1, 2, true) > 0) {
echo "1";
}
else {
echo "2";
}
?>

Element
12-31-2005, 03:41 AM
I want to copare $a, $b and make an echo result based on comparison result.

I tried something lik this, but itsn't not working, need a correction here.

<?
$a = abcde;
$b = BC;
if (substr_compare($a, $b, 1, 2, true) > 0) {
echo "1";
}
else {
echo "2";
}
?>

I made a script like this, becuase i have been asked about it, and i needed it myself, though apparently some moderater didn't find it useful. But of course they probably wouldn't because they're not learning PHP and don't know whats good for users or not.

I'd share the script with you but I reformatted my computer and its no longer on the forums. I'll try rewriting it, or seeing if its still on my host.

you could do something as simple as:



$a = "Foo Bar";
if(stristr(strtolower($a), "bar")) {
echo "Found bar!";
} else {
echo "No bar found!";
}

vinyl-junkie
12-31-2005, 03:46 AM
substr_compare is a feature of PHP5. Is that what you're using?

zeee
12-31-2005, 04:50 AM
Oh thnx element, i needed this alot.


substr_compare is a feature of PHP5. Is that what you're using?
yes

dumpfi
12-31-2005, 01:07 PM
Try to quote your strings.

dumpfi



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum