Ankündigung

Einklappen
Keine Ankündigung bisher.

preg_match_all() links

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • preg_match_all() links

    warum bringt mir diese funktion:
    Code:
    function get_links ($html)
    {
    	$pattern = '/(href|src|background)=("|\')(.*)(\\2)/siU';
    	preg_match_all($pattern,$html,$matches);
    	for ($i = 0;$i <= count($matches[3]);$i++)
    	{
    		$links[$i] = $matches[3][$i];
    	}
    	return $links;
    }
    immer nur einen link? egal wieviele href oder src attribute innerhalb von $html sind?
    http://www.silvercoding.de
    ------------
    ElePHPant Edit

  • #2
    Re: preg_match_all() links

    Zitat von konsti
    warum bringt mir diese funktion:
    Code:
    $pattern = '/(href|src|background)=("|\')(.*)(\\2)/siU';
    immer nur einen link? egal wieviele href oder src attribute innerhalb von $html sind?
    Zitat von Handbuch
    m (PCRE_MULTILINE)
    By default, PCRE treats the subject string as consisting of a single "line" of characters (even if it actually contains several newlines). The "start of line" metacharacter (^) matches only at the start of the string, while the "end of line" metacharacter ($) matches only at the end of the string, or before a terminating newline (unless D modifier is set). This is the same as Perl.

    When this modifier is set, the "start of line" and "end of line" constructs match immediately following or immediately before any newline in the subject string, respectively, as well as at the very start and end. This is equivalent to Perl's /m modifier. If there are no "\n" characters in a subject string, or no occurrences of ^ or $ in a pattern, setting this modifier has no effect.
    ->moved to Anfänger Forum

    Kommentar


    • #3
      1. nenn mir einen anfänger der überhaupt weiß, was preg_match_all macht
      2. klugscheißer nicht rum wenn du selbst keine ahnung hast, hab ich nämlich alles schon probiert
      http://www.silvercoding.de
      ------------
      ElePHPant Edit

      Kommentar


      • #4
        Diesen Ton brauchst du wohl auch nicht anzuschlagen, v.a. auch wenn deine Behauptung doch etwas gewagt ist. Folgender Code
        Code:
        <?php
        	$text = 'href="www.phpfriend.de" src=\'bild.jpg\' background=\'../bilder/baum.jpg\'';
        	$regex = '/(href|src|background)=("|\')(.*)(\\2)/siU';
        	preg_match_all($regex, $text, $found);
        	var_dump($found[3]);
        ?>
        produziert den folgenden Output
        array(3) { [0]=> string(10) "www.phpfriend.de" [1]=> string( "bild.jpg" [2]=> string(1 "../bilder/baum.jpg" }
        Wo ist also das Problem? Es funktioniert doch problemlos, auch wenn ich die Regex so formulieren würde (ist aber nebensächlich)
        Code:
        '/(href|src|background)=(["\'])(.+)(\\2)/siU'
        Gruss
        L

        Kommentar


        • #5
          Zitat von konsti
          1. nenn mir einen anfänger der überhaupt weiß, was preg_match_all macht
          Steht im Handbuch.
          2. klugscheißer nicht rum wenn du selbst keine ahnung hast, hab ich nämlich alles schon probiert
          a. isses mir Wurscht, was Du alles probiert hast, wenn Du keine aussagekräftigen Beispiele bringst
          b. würde ich an Deiner Stelle auf jedem Fall den Parameter m wie multiline verwenden.

          Kommentar

          Lädt...
          X