Translate Perl to PHP for me please

Discussion in 'PHP' started by ednit, Apr 1, 2007.

  1. #1
    I know almost nothing about php, and I can't for the life of me figure out how to translate this correctly. Here's a perl version of what I want to do in php:

    
    $request = "$ENV{'REQUEST_URI'}";
    
    if (($request ne "/")&&($request !~ m/index.php/)) {print $myadsensecode;}
    
    
    Code (markup):
    Here is the PHP code I have now:

    
    <!-- ONLY SHOW THIS TEXT ON SUB PAGES -->
    <?php
    $AC_Onlyshow = $_SERVER['REQUEST_URI'];
    
    $ADSENSE_CODE = <<<ADSENSECODE
    <div style="display:block;float:left;padding:5px;">
    <!-- ADSENSE BLOCK -->
    </div>
    ADSENSECODE;
    ?>
    
    <!-- END ONLY SHOW THIS TEXT ON SUB PAGES -->
    
    <!-- LATER ON IN THE PAGE -->
    
    <?php if ( $AC_Onlyshow != "/") {
        echo "$ADSENSE_CODE";
    }
    ?>
    
    
    Code (markup):
    It's for a wordpress blog - I want the adsense to show up on individual pages, and that part works: but my problem is when searches are done: it'll show the adsense code for every post which would cause issues with Google . . .

    The only thing I need translated is this part:

    &&($request !~ m/index.php/)

    Any help would be appreciated.

    thanks.
     
    ednit, Apr 1, 2007 IP
  2. MrSupplier

    MrSupplier Peon

    Messages:
    141
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I've tried bare bones Babelfish :) translation for
    &&($request !~ m/index.php/) and got that:

     && ( strpos($request,'index.php') === false ) 
    Code (markup):
    Hope that helps.
     
    MrSupplier, Apr 1, 2007 IP
  3. ednit

    ednit Peon

    Messages:
    152
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,

    I tried the above code. . . and wordpress didn't like it too much.

    I think what I'm looking for is something that uses preg_match - but I don't know how to create regular expressions in php - only perl.

    Nor do I know how to do the if ((!$something)&&($not eq "$somethingelse")) {&whatever;} - I'm not exactly sure if the && is correct.

    Any more ideas on this?
     
    ednit, Apr 2, 2007 IP
  4. ednit

    ednit Peon

    Messages:
    152
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I found what I was looking for, and I wanted to post the solution here in case someone else was looking for it to.

    Here is the translation of what I was looking for:

    <?php if ( $AC_Onlyshow != '/' && (!preg_match("/\/index.php+?/","$AC_Onlyshow")))
    {
        echo "$ADSENSE_CODE";
    }
    
    ?>
    
    Code (markup):
    While this does what I was trying to do, namely removing the adsense code from the search page. . . it does nothing for the archives nor the category pages. . . .

    I guess maybe I should just look for an already developed plugin, but it was fun to try & pick up some php in the meantime.

    Thanks.
     
    ednit, Apr 19, 2007 IP