A problem with '"'

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

    A problem with '"'

    I have written a code and can't figure what is wrong, the code will
    read a content of a file and cut all the emails from it,then echo them,
    but I have a problem with '"' charecter I think..
    Take a look:
    *************** *************
    <?php
    $url="http://www.bihstudenti .com/kontakt.php";
    $lines = file_get_conten ts($url);
    $done=explode(" @",$lines);
    for($i=0;$i<cou nt($done)+1;$i+ +)
    {
    $j=$i+1;
    $a=strrpos($don e[$i],":");
    $b=strrpos($don e[$i],">");
    $c=strpos($done[$j],chr(34));
    $d=strpos($done[$j],"<");
    $front=$done[$i];
    $back=$done[$j];
    if($a>$b){
    if($c<$d){
    echo "Line $i
    ".substr($front ,strrpos($front ,":")+1)."@".su bstr($back,0,st rpos($back,chr( 34)))."<br>";
    }else{
    echo "Line $i
    ".substr($front ,strrpos($front ,":")+1)."@".su bstr($back,0,st rpos($back,"<") )."<br>";
    }
    }else{
    if($c<$d){
    echo "Line $i
    ".substr($front ,strrpos($front ,">")+1)."@".su bstr($back,0,st rpos($back,chr( 34)))."<br>";
    }else{
    echo "Line $i
    ".substr($front ,strrpos($front ,">")+1)."@".su bstr($back,0,st rpos($back,"<") )."<br>";
    }
    }
    }
    ?>
    *************** *************
    I am looking at www.bihstudenti.com/kontakt.php content..
    Please help, do any one have a clue what is wrong..

  • Ewoud Dronkert

    #2
    Re: A problem with '&quot;'

    NurAzije wrote:[color=blue]
    > read a content of a file and cut all the emails from it,then echo them,[/color]

    Sorry, can't be bothered to check the code :) but try this:

    $data = file_get_conten ts('http://www.bihstudenti .com/kontakt.php');
    $match = array();
    preg_match_all( '/mailto:([^"]+)">/', $data, $match);
    print_r($match[1]);

    See http://php.net/preg-match-all

    --
    E. Dronkert

    Comment

    • NurAzije

      #3
      Re: A problem with '&quot;'

      It have succeded for the after mailto: ones, thank you very much, I am
      a beginner in PHP, I dont know to play with these '/mailto:([^"]+)">/'
      is there some tutorials to lern this about charecters or something..
      Thank you...

      Comment

      • Ewoud Dronkert

        #4
        Re: A problem with '&quot;'

        NurAzije wrote:[color=blue]
        > a beginner in PHP, I dont know to play with these '/mailto:([^"]+)">/'[/color]

        It's a "Regular Expression".
        Start at http://php.net/manual/en/ref.pcre.php

        --
        E. Dronkert

        Comment

        • Iván Sánchez Ortega

          #5
          Re: A problem with '&quot;'

          -----BEGIN PGP SIGNED MESSAGE-----
          Hash: SHA1

          NurAzije wrote:
          [color=blue]
          > $lines = file_get_conten ts($url);
          > $done=explode(" @",$lines);[/color]

          I think here lies your problem. explode() expects its second parameter to be
          an string, but you are feeding it an array (file() always returns an
          array). As a result of the automatic type casting, $done may be empty
          everytime yourun the script.

          You can either:
          - - Use array_map to apply the explode() function to every element from
          $lines, and then array_merge the results,
          - - or use file_get_conten ts() instead of file(), that returns a string.

          As usual, more information in php.net/manual ...

          - --
          - ----------------------------------
          Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net


          Proudly running Debian Linux with 2.6.12-1-686 kernel, KDE3.4.2, and PHP
          5.0.5-3 generating this signature.
          Uptime: 12:47:15 up 15:50, 2 users, load average: 0.38, 0.43, 0.35

          -----BEGIN PGP SIGNATURE-----
          Version: GnuPG v1.4.2 (GNU/Linux)

          iD8DBQFDWhlK3jc Q2mg3Pc8RAsboAJ 9jjcxTe0DLSC4UG hctFISP3ItfBwCf VENu
          c+TD9oiDNhjcYxA wYQoo5Qw=
          =knA6
          -----END PGP SIGNATURE-----

          Comment

          • Iván Sánchez Ortega

            #6
            Re: A problem with '&quot;'

            -----BEGIN PGP SIGNED MESSAGE-----
            Hash: SHA1

            NurAzije wrote:

            Oh, and, by the way:
            [color=blue]
            > for($i=0;$i<cou nt($done)+1;$i+ +)[/color]

            Always use foreach() to transverse array: it's quite more secure (doesn't
            miss any array keys, even if non-numeric) and compact (i.e. readable).

            [...][color=blue]
            > $a=strrpos($don e[$i],":");[/color]

            Also, if you are not going to use variable expansion (putting a variable
            name inside a double-quote-enclosed string), use single quotes instead. It
            saves the script a very small little bit of parsing time (that always
            helps).

            - --
            - ----------------------------------
            Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

            "If you haven't got anything nice to say about anybody, come sit next to
            me."
            - Alice Roosevelt Longworth (1884-1980)
            -----BEGIN PGP SIGNATURE-----
            Version: GnuPG v1.4.2 (GNU/Linux)

            iD8DBQFDWhnT3jc Q2mg3Pc8RAoyYAJ 9ozRD4EwSuHe9lK 3QSUFIe2+ZIiQCf fluZ
            /b3Z0xAOSf64CnbG 3z8tFK0=
            =SdHn
            -----END PGP SIGNATURE-----

            Comment

            • Ewoud Dronkert

              #7
              Re: A problem with '&quot;'

              Iván Sánchez Ortega wrote:[color=blue]
              > NurAzije wrote:[color=green]
              >> $lines = file_get_conten ts($url);
              >> $done=explode(" @",$lines);[/color]
              >
              > I think here lies your problem. explode() expects its second parameter to be
              > an string, but you are feeding it an array (file() always returns an
              > array). [...]
              > or use file_get_conten ts() instead of file(), that returns a string.[/color]

              He did!

              --
              E. Dronkert

              Comment

              • NurAzije

                #8
                Re: A problem with '&quot;'

                The expresions way is better, thanks ..
                Now I must construct an expression that has an @ at the middle, and ><
                at the sides, or spaces or " ", there is a list but the base is the
                same ..

                Comment

                • NurAzije

                  #9
                  Re: A problem with '&quot;'

                  I am trying to write the expression like this, but something seems
                  wrong:
                  preg_match_all( '/(<|:| |").+@.+\....(> | |")/', $data, $match);
                  as follows :
                  (<|:| |") -- < or : or space or "
                  ..+ -- any number of any charecters
                  @ -- is the @ in the email
                  ..+ -- any number of any charecters
                  \. -- an escape for the dot
                  .... -- any three characters
                  (>| |") -- > or space or "

                  Any help please

                  Comment

                  • Ewoud Dronkert

                    #10
                    Re: A problem with '&quot;'

                    NurAzije wrote:[color=blue]
                    > preg_match_all( '/(<|:| |").+@.+\....(> | |")/', $data, $match);[/color]

                    Greedy/non-greedy problem, I guess. (Also, you should enclose the part
                    that you *do* want to match in brackets, or the matches won't show up as
                    separate entries in $match.) Try '/[a-z0-9_.+-]+@[a-z0-9.-]+/i'.

                    --
                    E. Dronkert

                    Comment

                    • NurAzije

                      #11
                      Re: A problem with '&quot;'

                      I tried that but did not succed yet, I've written a more complexed one:
                      preg_match_all( '/(([A-Za-z0-9_\.-]+)@(?:[a-z0-9]+\-*(?:[a-z0-9A-Z]+)*\.)+[A-Za-z]{2,4})/',
                      $data, $match);
                      but even this one can't solve the problem, I need emails..
                      Thank you.

                      Comment

                      • Iván Sánchez Ortega

                        #12
                        Re: A problem with '&quot;'

                        -----BEGIN PGP SIGNED MESSAGE-----
                        Hash: SHA1

                        Ewoud Dronkert wrote:
                        [color=blue]
                        > Iván Sánchez Ortega wrote:[color=green]
                        >> NurAzije wrote:[color=darkred]
                        >>> $lines = file_get_conten ts($url);
                        >>> $done=explode(" @",$lines);[/color]
                        >>
                        >> or use file_get_conten ts() instead of file(), that returns a string.[/color]
                        >
                        > He did![/color]

                        Must read the code slower and more carefully.... :-S

                        - --
                        - ----------------------------------
                        Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

                        Un ordenador no es un televisor ni un microondas, es una herramienta
                        compleja.
                        -----BEGIN PGP SIGNATURE-----
                        Version: GnuPG v1.4.2 (GNU/Linux)

                        iD8DBQFDWjrH3jc Q2mg3Pc8RAvGRAK CEkOZa679KUgo91 lezuRGiWhZs0wCc CLBI
                        /YKgN9RAs8YoeETb mnBmvTI=
                        =nHM4
                        -----END PGP SIGNATURE-----

                        Comment

                        • Tim Roberts

                          #13
                          Re: A problem with '&quot;'

                          "NurAzije" <nurazije@gmail .com> wrote:[color=blue]
                          >
                          >I have written a code and can't figure what is wrong, the code will
                          >read a content of a file and cut all the emails from it,then echo them,
                          >but I have a problem with '"' charecter I think..[/color]

                          You have no idea how hard this problem really is. The regular expression
                          which completely matches all possible RFC822 e-mail addresses is more than
                          6,000 characters long.
                          --
                          - Tim Roberts, timr@probo.com
                          Providenza & Boekelheide, Inc.

                          Comment

                          • NurAzije

                            #14
                            Re: A problem with '&quot;'

                            is it something like this :
                            ************
                            <?
                            $data = file_get_conten ts('http://www.bihstudenti .com/kontakt.php');
                            $match = array();
                            preg_match_all( '/^([a-zA-Z0-9_\-])+(\.([a-zA-Z0-9_\-])+)*@((\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\]))|((([a-zA-Z0-9])+(([\-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([\-])+([a-zA-Z0-9])+)*))$/',
                            $data, $match);
                            print_r($match[1]);
                            ?>
                            *************** *******
                            But I still get this result in printout :
                            Array()

                            What to do more..
                            Any ideas

                            Comment

                            • Ewoud Dronkert

                              #15
                              Re: A problem with '&quot;'

                              NurAzije wrote:[color=blue]
                              > print_r($match[1]);
                              >
                              > But I still get this result in printout :
                              > Array()[/color]

                              It's definitely not the right expression. But first of all try
                              print_r($match) and go from there. (Not ...[1].)

                              --
                              E. Dronkert

                              Comment

                              Working...