cj333
cj333

Reputation: 2609

PHP How to get the text part before <br>?

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

Answers (2)

azat
azat

Reputation: 3565

Or like this

preg_match('@(?P<before>.+)(?:<br\s*/>|<br\s*>)@Uis', $str, $matches);
echo $matches['before'];

Upvotes: 3

fatnjazzy
fatnjazzy

Reputation: 6152

$str  = "text part1 <br />text part2";

$arr = explode("<br />",$str);

print $arr[0];//text part1

Upvotes: 7

Related Questions