Couldn’t find anything about this on the internet, or stackoverflow?!?
Basic Example:
A great example of what I want to know is, how would you create an if statement that returns true if it finds a word or phrase in a sentence.
Another Example:
Let’s say we have an IP blocklist in an external file. So I presume we’ll need to use file_get_contents somewhere in the if statement.
// IP Blocklist
118.92.00
119.92.11
125.23.10
Ok so that’s our example IP blocklist. How would you create an if statement that is able to find the middle IP (119.92.11), even though there is other content there (keeping in mind it could very well change!)?
Your two examples would require two different techniques to be reliable.
Example 1 simply requires
strpos():You could use
stripos()instead if you want to match in a case-insensitive manner.For example two it would be better to use an array. This is because the
strpos()approach would match11.22.22.11if11.22.22.110was in the array – and you don’t want this.Instead, you would do something like this, using
in_array():