Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    substr_compare ><=

    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";
    }
    ?>

  • #2
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by zeee
    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:

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

    Last edited by Element; 12-31-2005 at 03:45 AM.

  • #3
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,100
    Thanks
    2
    Thanked 23 Times in 23 Posts
    substr_compare is a feature of PHP5. Is that what you're using?
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #4
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh thnx element, i needed this alot.

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

  • #5
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Try to quote your strings.

    dumpfi


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •