Raketenwilli: Ziffern fischen per RegEx

Beitrag lesen

Meinst Du sowas?

<?php
header( 'Content-Type:text/plain' );
$strings = [
    'Foo bar Projekt 12 3Kram',
    'Foo bar Projekt 123Kram',
    'Foo bar Projekt 1 23Kram',
    'Foo bar Projekt12 3 Kram',
    'Foo bar Projekt123 Kram',
    'Foo bar Projekt1 23 Kram'
];
$strings[] = implode( PHP_EOL, $strings );

$pattern = '/Projekt *[0-9 ]+/i';

$i = 0;
foreach( $strings as $string ) {
	$k = 0;
    preg_match_all( $pattern, $string, $arr ) . PHP_EOL;
    $i++;
    echo PHP_EOL . $i . ". String:\t\"" . $strings[$i-1] . '"' . PHP_EOL;
    foreach ( $arr as $a ) {
		foreach ( $a as $s ) {
			$k++;
			echo "\t" . $k . ". Fund:\t" . str_replace( ' ', '', $s ) . PHP_EOL;
		}
	}
}