1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

coding help required from expert!!!

Discussion in 'PHP' started by zak, Apr 5, 2005.

  1. #1
    I have a simple problem!

    I am not very well versed in PHP, JAVA is my cup of cofee...

    Any way, what I am trying to do (using PHP) is simple

    I would like to get the URL of the page and store it in a variable.

    I would then like to search the variable for a string

    e.g

    If I have a domain www.somedomain.com/somepage.php

    Then I would like to store in in $somevariable

    I would then like to check $somevariable for the string 'somepage'

    can anyone help!!!! :confused:
     
    zak, Apr 5, 2005 IP
  2. david_sakh

    david_sakh Peon

    Messages:
    1,225
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #2
    does this work for you?

    $path=$_SERVER["PHP_SELF"];
    PHP:
    ok now to check for the string somepage....checking....

    $somepage="document"; 
    if (strpos($path,$somepage)!=0)
     echo "Found it.";
    PHP:
    does that work? I don't work with strings much and I'm something of a php newbie myself...

    If it doesn't work, I'm sure rvarcher or JD or Shawn will clear things up for you.
     
    david_sakh, Apr 5, 2005 IP
  3. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If $somepage is found at the beginning of $path, strpos() will return 0. You need to check for false with the type-sensitive equality operator.
    $somepage="document"; 
    if (strpos($path,$somepage)!==false) {
        echo "Found it.";
    }
    PHP:
     
    exam, Apr 5, 2005 IP
  4. david_sakh

    david_sakh Peon

    Messages:
    1,225
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ooo right.

    thx.
     
    david_sakh, Apr 5, 2005 IP
  5. zak

    zak Peon

    Messages:
    175
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks, I've got it to work!!!
     
    zak, Apr 6, 2005 IP
    david_sakh likes this.