Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
wobei "*?" keinen großen Sinn macht, oder?<h2>(.*?)</h2>
<?php
$text = '<h1>foo</h1>
<h2>bar</h2>
<p>mooh</p>
<h2>bla</h2>
<p>blub</p>
';
if (preg_match_all('/<h2>(.*)<\/h2>/i', $text, $out)) {
foreach ($out[1] as $i => $title) {
echo 'Der ' . ($i+1) . '. H2-Titel lautet : ' . $title . '<br />' . chr(10);
}
}
?>
preg_match_all('/<h2>(.*)<\/h2>/i', '<h2>Titel1</h2> ... <h2>Titel2</h2>', $out)
--> 1 Match, $1 = 'Titel1</h2> ... <h2>Titel2'
preg_match_all('/<h2>(.*?)<\/h2>/i', '<h2>Titel1</h2> ... <h2>Titel2</h2>', $out)
--> 2 Matches, erster Match: $1 = 'Titel1', 2. Match: $1 = 'Titel2'
However, if a quantifier is followed by a question mark, then it becomes lazy, and instead matches the minimum number of times possible, so the pattern /\*.*?\*/ does the right thing with the C comments. The meaning of the various quantifiers is not otherwise changed, just the preferred number of matches. Do not confuse this use of question mark with its use as a quantifier in its own right. Because it has two uses, it can sometimes appear doubled, as in \d??\d which matches one digit by preference, but can match two if that is the only way the rest of the pattern matches.
Deswegen: Lieber den Pattern (.*?) verwenden.
if (preg_match_all('/<h2>(.*)<\/h2>/U', $text, $out)) {