preg_replace help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    preg_replace help

    hey guys i am using curl to get source code from a site but i need to know how to use preg_replace to remove this code
    Code:
    <script type="text/javascript">
    		    (function() {
    		    var em = document.createElement('script'); em.type = 'text/javascript'; em.async = true;
    		    em.src = ('https:' == document.location.protocol ? 'https://za-ssl' [^] : 'http://za-cdn' [^]) + '.effectivemeasure.net/em.js';
    		    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(em, s);
    		    })();
    	    </script>
    and this last one im also lost with
    Code:
    <a href="http://ad.mo.doubleclick.net/dartproxy/click.handler?destination=http%3A%2F%2Fm.sabc.co.za%2Fsabc%2Fmobile%2Fjsp%2Ftv.jsp&click=http%3A%2F%2Fad-emea.doubleclick.net%2Fclick%3Bh%3Dv8%2F3c6e%2F3%2F0%2F*%2Fr%3B222803474%3B0-0%3B0%3B45967855%3B1-468%2F60%3B35745356%2F35763197%2F1%3B%3B%7Eokv%3D%3Bdcopt%3Dmd%3Bkey1%3Dtop%3Bkey2%3Dbottom%3Bmv1%3D438%3Bmv2%3D203%3Bmv3%3D61%3Bmmanuf%3Dgeneric%3Bmmodel%3Diris+browser%3Bmvideost%3Dfalse%3Bmanigif%3Dtrue%3B%3B%7Esscs%3D%3Fhttp%3A%2F%2F"><img alt="TV Schedules" src="http://s0.2mdn.net/2661318/MID_1258915_L-TS.jpg"></a>
    thanks in advance
    zain

    #2
    use this.
    PHP Code:
    $d=preg_replace("|<script type=\"text/javscript\"(*.?)</script>|is","",$d); 
    It will remove all javascript code matching ths sequence.
    Last edited by arnage; 04.10.12, 17:10.

    Comment


      #3
      Heres code

      Originally posted by zain View Post
      hey guys i am using curl to get source code from a site but i need to know how to use preg_replace to remove this code
      Code:
      <script type="text/javascript">
      		    (function() {
      		    var em = document.createElement('script'); em.type = 'text/javascript'; em.async = true;
      		    em.src = ('https:' == document.location.protocol ? 'https://za-ssl' [^] : 'http://za-cdn' [^]) + '.effectivemeasure.net/em.js';
      		    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(em, s);
      		    })();
      	    </script>
      and this last one im also lost with
      Code:
      <a href="http://ad.mo.doubleclick.net/dartproxy/click.handler?destination=http%3A%2F%2Fm.sabc.co.za%2Fsabc%2Fmobile%2Fjsp%2Ftv.jsp&click=http%3A%2F%2Fad-emea.doubleclick.net%2Fclick%3Bh%3Dv8%2F3c6e%2F3%2F0%2F*%2Fr%3B222803474%3B0-0%3B0%3B45967855%3B1-468%2F60%3B35745356%2F35763197%2F1%3B%3B%7Eokv%3D%3Bdcopt%3Dmd%3Bkey1%3Dtop%3Bkey2%3Dbottom%3Bmv1%3D438%3Bmv2%3D203%3Bmv3%3D61%3Bmmanuf%3Dgeneric%3Bmmodel%3Diris+browser%3Bmvideost%3Dfalse%3Bmanigif%3Dtrue%3B%3B%7Esscs%3D%3Fhttp%3A%2F%2F"><img alt="TV Schedules" src="http://s0.2mdn.net/2661318/MID_1258915_L-TS.jpg"></a>
      thanks in advance
      zain
      Code:
      $hammad = preg_replace('/<script(.*?)<\/script>/is','',$hammad);
      Code:
      $hammad = preg_replace('/<a href="http:\/\/ad(.*?)<\/a>/is','',$hammad);

      Comment


        #4
        Originally posted by mansi View Post
        use this.
        $d=preg_replace("|<script type=\"text/javscript\"(*.?)</script>|is","",$d);
        It will remove all javascript code matching ths sequence.
        you would get problems using this code. as you need to make sure you escape slashes.


        Originally posted by Hammad View Post
        Code:
        $hammad = preg_replace('/<script(.*?)<\/script>/is','',$hammad);
        Code:
        $hammad = preg_replace('/<a href="http:\/\/ad(.*?)<\/a>/is','',$hammad);
        i would use this version hammad has offered up. its correct
        <?php
        include ('Ghost');
        if ($Post == true) {
        echo '

        sigpic
        alt='coding-talk.com!!' />';
        echo 'Sharing Is Caring!';
        } else {
        echo '

        alt='the username GHOST has been comprimised!' />';
        echo 'OMG SOMEBODY HELP ME!!';
        }
        ?>

        Comment


          #5
          thank you guys

          Comment


            #6
            Originally posted by Ghost View Post
            Originally posted by mansi View Post
            use this.
            $d=preg_replace("|<script type=\"text/javscript\"(*.?)</script>|is","",$d);
            It will remove all javascript code matching ths sequence.
            you would get problems using this code. as you need to make sure you escape slashes.
            You don't need to escape the forward slashes if the delimiter isn't a forward slash.
            PHP: Delimiters - Manual

            Comment


              #7
              Tube is a alternative meta-character so it shouldn't be used as delimiter.
              <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

              Comment


                #8
                Originally posted by Andrew. View Post
                You don't need to escape the forward slashes if the delimiter isn't a forward slash.
                PHP: Delimiters - Manual
                ok your right to some extent.
                but if you took the time to read the 2 comments left in that link you posted.
                you'd see its not a wise choice or idea to use meta-characters in the regular expression
                as a delimiter, thats not saying you cant use them. i was just clearly stating that the option
                hammad offered up was clearly the better of the 2 choices given to this original poster.
                <?php
                include ('Ghost');
                if ($Post == true) {
                echo '

                sigpic
                alt='coding-talk.com!!' />';
                echo 'Sharing Is Caring!';
                } else {
                echo '

                alt='the username GHOST has been comprimised!' />';
                echo 'OMG SOMEBODY HELP ME!!';
                }
                ?>

                Comment


                  #9
                  Try to avoid using these:

                  . \ + * ? [ ^ ] $ ( ) { } = ! < > | : -
                  <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

                  Comment

                  Working...
                  X