help with preg_match

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

    help with preg_match

    i want to split an total url like it is in format :
    HTML Code:
    <a href='http://red.domain.net/ck.php?id=o2SjLKWuoKZ9Uy9sLzShozIlnJD9ZGNkZwRlK196o25ynJD9ZwtlAy9sL2V9ZmyvZmSxAmEzAz'>test test test etc..</a>
    i want to split it and just want to get http://red.domain.net/ck.php?id=o2SjLKWuoKZ9Uy9sLzShozIlnJD9ZGNkZwRlK196 o25ynJD9ZwtlAy9sL2V9ZmyvZmSxAmEzAz
    what will be this ?
    i tried like:
    PHP Code:
    $data "<a href='http://red.domain.net/ck.php?id=o2SjLKWuoKZ9Uy9sLzShozIlnJD9ZGNkZwRlK196o25ynJD9ZwtlAy9sL2V9ZmyvZmSxAmEzAz'>test test test etc..</a>";
    preg_match('@href="(.+?)"@is',$data,$match);
    $get $match[1]; 
    but not successful,
    can any one help?

    #2
    It was in my bookmarks, it's will help to cope up with problem
    Coding Horror: The Problem With URLs
    I need some facebook likes, can you please help me
    http://facebook.com/softwarefreakin
    I noticed social media is really powerful
    Well DONE is better than well SAID

    Comment


      #3
      not clear yet

      Comment


        #4
        Originally posted by razor View Post
        not clear yet
        hmm, try ds
        PHP Code:
        <?php
        $data 
        "<a href='http://red.domain.net/ck.php?id=o2SjLKWuoKZ9Uy9sLzShozIlnJD9ZGNkZwRlK196o25ynJD9ZwtlAy9sL2V9ZmyvZmSxAmEzAz'>test test test etc..</a>"
        preg_match('@<a href=[\'|"](.+)[\'|"]>@is',$data,$match); 
        print_r($match);
        I need some facebook likes, can you please help me
        http://facebook.com/softwarefreakin
        I noticed social media is really powerful
        Well DONE is better than well SAID

        Comment


          #5
          Originally posted by softwarefreak View Post
          hmm, try ds
          PHP Code:
          <?php
          $data 
          "<a href='http://red.domain.net/ck.php?id=o2SjLKWuoKZ9Uy9sLzShozIlnJD9ZGNkZwRlK196o25ynJD9ZwtlAy9sL2V9ZmyvZmSxAmEzAz'>test test test etc..</a>"
          preg_match('@<a href=[\'|"](.+)[\'|"]>@is',$data,$match); 
          print_r($match);
          that should be $match[1] ...
          thanks dude for the help...

          Comment


            #6
            Originally posted by razor View Post
            that should be $match[1] ...
            thanks dude for the help...
            print_r() is the best way to work with arrays, welcome anyways

            Added after 10 minutes:

            BTW, here's the code to match all the anchor links from a page

            PHP Code:
            <?
            $data = file_get_contents("http://youtube.com"); 
            preg_match_all('@<a href=[\'|"](.+)[\'|"]@Uis',$data,$match);
            $links = $match[1]; 
            $count = count($links);
            for ($i=0; $i < $count; $i++) 

                echo $links[$i] . "<br />\n";
            }
            Last edited by softwarefreak; 31.08.12, 19:03.
            I need some facebook likes, can you please help me
            http://facebook.com/softwarefreakin
            I noticed social media is really powerful
            Well DONE is better than well SAID

            Comment


              #7
              explode();

              This is very easy,

              PHP Code:
              $data "<a href='http://red.domain.net/ck.php?id=o2SjLKWuoKZ9Uy9sLzShozIlnJD9ZGNkZwRlK196o25ynJD9ZwtlAy9sL2V9ZmyvZmSxAmEzAz'>test test test etc..</a>"

              $var explode("'"$data);


              echo 
              $var[1]; 
              this will output what you exactly need...........


              I'm Proud to be a Sri Lankan!

              Comment

              Working...
              X