0

I have a link stored in a variable called $word like this:

$word = www.stack.com/angraze_mjhay_batao/help.php

I want to put a condition that if stack is found somewhere in the variable $word to do certain things. I have done searching but everywhere there are functions to match words in the string. I cannot find any PHP function that does this job.

Serving Quarantine period
  • 66,345
  • 10
  • 43
  • 85
Sppidy
  • 193
  • 2
  • 2
  • 11

1 Answers1

5

strpos should do the trick:

if (strpos($word, 'stack') !== false) {
    // do things...
}
Mureinik
  • 252,575
  • 45
  • 248
  • 283
  • @CasimiretHippolyte indeed, how embarrassing. Fixed. Thanks for noticing! – Mureinik Jun 07 '15 at 21:06
  • He likes posting things :P – Goodbye StackExchange Jun 07 '15 at 21:06
  • Please avoid changing code in edits (Other than whitespace/fixing formatting), especially if it changes the functionality. I know strings are normally surrounded by quotes, or single quotes, but this may be another issue the OP is having, and by editing it, you're assuming the author quoted it properly, and things may still not work right for him. – Goodbye StackExchange Jun 07 '15 at 21:10
  • @FrankerZ fair enough. Carelessly just fixed it, but you are correct, that was a bad edit. Reverted the relevant parts (manually). – Mureinik Jun 07 '15 at 21:12
  • @Mureinik thanks for the help.btw how did you do that. i mean i tried posting it without that ignore line :P but they were not letting me post it. how they let you post it – Sppidy Jun 07 '15 at 21:31