s modifier: use . to match characters across multiple lines. : preg_match « String « PHP
- PHP
- String
- preg_match
s modifier: use . to match characters across multiple lines.
//access the first and last words of a string
<?
$text = "start with this line\nand you will reach\na conclusion in the end\n";
if ( preg_match( "/^(\w+).*?(\w+)$/", $text, $array ) ) {
print "<pre>\n";
print_r( $array );
print "</pre>\n";
}
?>
Related examples in the same category