Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Senior Member
    Join Date
    Aug 2011
    Posts
    227
    Member #
    29153
    Liked
    4 times
    Here's what I have done but it is not doing anything.
    Code:
    if(strpos($title, "string looking for" != false)) {
       some code
      }

  2.  

  3. #2
    Senior Member
    Join Date
    Aug 2011
    Posts
    227
    Member #
    29153
    Liked
    4 times
    Never mind. I got it.

    Code:
    $holder = strpos($title, "string looking for");
    if($holder !== false) {
        some code
       }

  4. #3
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    Glenn ... and others using 'strpos' ....

    Be very careful about strpos if your "needle" (what you're searching for in the "haystack")
    happens to be found at the very first position (which is zero).

    When you check for 'false', it will be false. Not because it wasn't found, but because
    it was found at position 0 (zero is false). That can cause a lot of frustration.

    PHP considers 0 (zero) to be false and 1 (one) or NOT zero, to be true.

    The 0=false can 'getcha' in several PHP commands.

    To avoid this, always use === instead of == , or !== instead of != when you work with string compares:
    http://php.net/manual/en/function.strpos.php

    The PHP manual will usually show you the warning box when you view the command.


    I usually just look for a piece of the string that I know will never be in position zero.


  5. #4
    Senior Member Ganners's Avatar
    Join Date
    Feb 2011
    Location
    United Kingdom
    Posts
    415
    Member #
    27007
    Liked
    92 times
    You have many more options, I like to use strstr/stristr for this sort of thing. You could also use preg_match for more sophistication, though it's a little slower to run.
    Mark Gannaway Software Developer

    Recent Experiments
    - Backpropogation Neural Network language solving (http://ann.ganners.co.uk/)
    - Animated image to ASCII (http://google.ganners.co.uk/)
    - 3D Paper Characters (http://cybergame.ganners.co.uk/)
    - Anagram solving (http://roflol.co.uk/)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:20 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com