Author Topic: Detect a word within a string  (Read 677 times)

0 Members and 1 Guest are viewing this topic.

Offline d_barszczakTopic starter

  • Enthusiast
  • Posts: 188
  • Gender: Male
  • Integrated IT Systems Ltd
    • View Profile
    • integrateditsystems.co.uk - Your web solution
Detect a word within a string
« on: July 30, 2008, 05:04:34 AM »
Hi all,

Once again i have been tripped up by regex so hope you can help.

I have a hitcounter script that submits an id and the url of the page the script was run. I need to be able to detect a domain within the url i.e.

Code: [Select]
// Check to see if site is registered.

$domain = "integrateditsystems.co.uk";
$url = "http://www.integrateditsystems.co.uk/support";

if ($domain exists within $url) return true else false; // Help Me!!

When all else fails - Try reading the manual.

Offline lwc

  • Irregular
  • Posts: 35
    • View Profile
Re: Detect a word within a string
« Reply #1 on: July 30, 2008, 09:48:22 AM »
Why do you need regexp for this? Just use http://php.net/strpos

And remember the opposite of "===" is "!==".

Of course, if you just do what you want directly, it would also match "http://www.phishing.com/integrateditsystems.co.uk/trickedyou/".
« Last Edit: July 30, 2008, 09:51:07 AM by lwc »

Offline d_barszczakTopic starter

  • Enthusiast
  • Posts: 188
  • Gender: Male
  • Integrated IT Systems Ltd
    • View Profile
    • integrateditsystems.co.uk - Your web solution
Re: Detect a word within a string
« Reply #2 on: July 30, 2008, 01:33:02 PM »
Hmm good point...

I need to allow for sub domains so i could do something like "http://*.integrateditsystems.co.uk" or require a hitcounter for each sub domain.

Will have to have a think about this then.
When all else fails - Try reading the manual.