=("|\')?([^ "\']*)("|\')?.*>([^<]*)</A>'

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lecichy

    #1

    =("|\')?([^ "\']*)("|\')?.*>([^<]*)</A>'

    Hello.


    Well, I found this piece of code on php.net. Thats fine but where can i find
    explanation for all these ("|\')?([^ "\']*)("|\')?.*>([^<]*)' syntax so that
    I can construct my own rules for all kind of eregi preg and oter match
    functions ?



    Transform HTML links into plain-text "links" with the URL visible

    function AHREF2text($str ing) {
    return eregi_replace(' <A .*HREF=("|\')?([^ "\']*)("|\')?.*>([^<]*)</A>',
    '[\\4] (link: \\2)', $string);
    }


  • lecichy

    #2
    Re: =(&quot;|\')?([^ &quot;\']*)(&quot;|\')?. *&gt;([^&lt;]*)&lt;/A&gt;'

    And another simple question, maybe its the same answer.
    whats the syntax of eregi_replace if I want to match ( remove in this
    case ) few strings, not one:
    eregi_replace (("stringone" && "stringtwo" ), "", $source)
    Or it just requires whole eregi expression each time ?
    This ofcourse doesn't work but hope you know what I mean.


    Comment

    • Pedro

      #3
      Re: =(&quot;|\')?([^ &quot;\']*)(&quot;|\')?. *&gt;([^&lt;]*)&lt;/A&gt;'

      lecichy wrote:[color=blue]
      >And another simple question, maybe its the same answer.
      >whats the syntax of eregi_replace?[/color]

      You better switch to preg_ functions. They're faster and more powerful
      than ereg*
      [color=blue]
      >if I want to match ( remove in this case ) few strings, not one:
      >eregi_replac e (("stringone" && "stringtwo" ), "", $source)[/color]

      Try
      <?php
      $destin = preg_replace('/string(?:one|tw o)/i', '', $source)
      ?>


      /string(?:one|tw o)/i -- means:

      / # start of regex
      string # match "string literally"
      (?: # start a group but don't grab (no need for that)
      one # literal "one"
      | # OR
      two # literal "two"
      ) # end group
      /i # end regex, but match without regard to case


      see the preg_ function at


      Also try regex-coach from http://weitz.de/regex-coach/



      using the PCRE_EXTENDED modifier (x) you can put the regex and
      the comments in the source file

      <?php
      function AHREF2text($str ing) {
      return preg_replace(
      '@ # start of regex
      <a[ ] # literal "<a " (notice the space)
      [^<]* # any number of (any characters EXCEPT "<")
      href= # literal "href="
      ("|\')? # optional double OR single quote (grabbed)
      ([^"\']*) # any number of (anything BUT double
      ## OR single quote) (grabbed)
      ("|\')? # optional double OR single quote (grabbed)
      [^>]* # any number of (any characters EXCEPT ">")[color=blue]
      > # a literal ">"[/color]
      ([^<]*) # any number of anything BUT "<" (grabbed)
      </a> # literal "</a>"
      @ix', # end regex, caseless and extended

      '[\\4] (link: \\2)', $string);
      }

      // =============== ==============

      $x = 'At <a href="http://mysite.example. com/">my site</a> there
      are many <a href="http://examples.exampl e.com/">examples</a> :)';

      echo $x, '<hr />', htmlentities($x ), '<hr />', AHREF2text($x);
      ?>


      --
      I have a spam filter working.
      To mail me include "urkxvq" (with or without the quotes)
      in the subject line, or your mail will be ruthlessly discarded.

      Comment

      • lecichy

        #4
        Re: =(&quot;|\')?([^ &quot;\']*)(&quot;|\')?. *&gt;([^&lt;]*)&lt;/A&gt;'

        Thank you so much Pedro!


        Comment

        • Pedro

          #5
          Re: =(&quot;|\')?([^ &quot;\']*)(&quot;|\')?. *&gt;([^&lt;]*)&lt;/A&gt;'

          lecichy wrote:[color=blue]
          > Thank you so much Pedro!
          >[/color]

          You're welcome lecichy.
          Hope you enjoy regex's and the power they give you.

          --
          I have a spam filter working.
          To mail me include "urkxvq" (with or without the quotes)
          in the subject line, or your mail will be ruthlessly discarded.

          Comment

          • lecichy

            #6
            Re: =(&quot;|\')?([^ &quot;\']*)(&quot;|\')?. *&gt;([^&lt;]*)&lt;/A&gt;'

            [color=blue]
            > You're welcome lecichy.
            > Hope you enjoy regex's and the power they give you.
            >
            > --
            > I have a spam filter working.
            > To mail me include "urkxvq" (with or without the quotes)
            > in the subject line, or your mail will be ruthlessly discarded.[/color]

            Enjoy what ?

            Just kidding :P
            Now I'm so powerful that even my mom is afraid to come to my room ;)


            Comment

            • Pedro

              #7
              Re: =(&quot;|\')?([^ &quot;\']*)(&quot;|\')?. *&gt;([^&lt;]*)&lt;/A&gt;'

              lecichy wrote:[color=blue]
              > Now I'm so powerful that even my mom is afraid to come to my room ;)[/color]

              Moms have more power than all the regex gurus put together!

              --
              I have a spam filter working.
              To mail me include "urkxvq" (with or without the quotes)
              in the subject line, or your mail will be ruthlessly discarded.

              Comment

              Working...