Results 1 to 3 of 3
  1. #1
    ABW Ambassador Doug247's Avatar
    Join Date
    January 18th, 2005
    Location
    DE USA
    Posts
    931
    Search for a String in a URL
    Ok, I prety sure I did this one before but can not remember how.

    I basically what to search the current URL for the existance of a string then if it exists take an action.

    Here is what I have

    PHP Code:
    <?php 
                $pattern 
    '/MySearchString/';
                if (
    preg_match($pattern,$PATH_INFO)) {
                
    $ad addslashes('<Banner Add Link Information></a>');
                }
                echo 
    $ad;
                
    ?>
    Can any one see what I am missing?

    TIA
    Thanks,
    Doug

  2. #2
    ABW Ambassador superCool's Avatar
    Join Date
    April 23rd, 2008
    Location
    Texas
    Posts
    1,268
    not sure what you're missing, but superCool uses strpos and PHP_SELF. maybe this will work for you?

    if(isset($_SERVER['PHP_SELF']) && strpos($_SERVER['PHP_SELF'], $pattern) >= 0) {


    If this is stupid, please school superCool!!

    good luck


    fyi - the above is not exactly what superCool uses. my code is looking for the lack of a value, so the >= is actually <=. didn't think that would matter, but looking at the doc for strpos it might...??
    Last edited by superCool; August 26th, 2008 at 01:00 PM. Reason: added fyi

  3. #3
    Member Working Mom's Avatar
    Join Date
    May 18th, 2008
    Location
    Delaware
    Posts
    102
    It looks good to me...

    Reminds me of the Old "How to Shoot Yourself in the foot in any programming language" Thread:
    PHP
    You shoot yourself in the foot with a gun made with pieces from 300 other guns.

    You shoot yourself in the foot, but nobody can understand how you did it. Six months later, neither can you."
    (But then again, it's all Greek to me...)

    -WM

  4. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Question about URL string
    By Eric Ewe in forum Search Engine Optimization
    Replies: 0
    Last Post: June 14th, 2008, 11:19 AM
  2. Search String For ZhotelZ
    By Jon Nunez in forum AffiliateManager.com
    Replies: 0
    Last Post: May 29th, 2007, 03:32 PM
  3. Displaying search string in URL on web page?
    By Azam in forum Programming / Datafeeds / Tools
    Replies: 2
    Last Post: May 1st, 2007, 11:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •