Reputation: 131
i have code like this:
<?
$source = '!Hello, this is !PHP!HTML !@language';
preg_match("'!(.*?)'si", $source, $match);
if($match) print_r($match);
?>
and i want to get result like:
!Hello
!PHP
!HTML
!@language
anyone can help?
Upvotes: 0
Views: 67
Reputation: 872
Use this instead of preg_match
preg_match_all("/![@a-z]*/si", $source, $match);
preg_match
returns only first match.
Upvotes: 0
Reputation: 42450
<?php
$haystack = "!Hello, this is !PHP!HTML !@language";
$needle = "/!([^\s\!,])*/";
$matches;
preg_match_all($needle,$haystack,$matches);
foreach($matches[0] as $match)
{
echo $match . "\n";
}
?>
Upvotes: 0
Reputation: 160883
$source = '!Hello, this is !PHP!HTML !@language';
preg_match_all("~![^(!|\s|,)]*~si", $source, $match);
if($match) print_r($match);
Upvotes: 0
Reputation: 16115
Change to:
preg_match_all("/![a-z@]*/i", $source, $match);
Also see this example.
Upvotes: 4