Reputation: 2609
There are some text, format like:
text part1
<br />
text part2
How to use php regular-expression get the only the text: text part1
? Thanks a lot.
Upvotes: 1
Views: 1570
Reputation: 3565
Or like this
preg_match('@(?P<before>.+)(?:<br\s*/>|<br\s*>)@Uis', $str, $matches);
echo $matches['before'];
Upvotes: 3
Reputation: 6152
$str = "text part1 <br />text part2";
$arr = explode("<br />",$str);
print $arr[0];//text part1
Upvotes: 7