This question already has an answer here:
The following preg_replace checks a line beginning with a *
, and puts html tags around it. This works well, the only problem with this is, it'll work only if there is one line supplied to it and not if there's more than one.
I've tried adding \s
and m
to it, but nothing will get it to work. What can be done to get this working?
$str = <<< EOF
*Portfolio
Our work includes...
*Company Profile
Acme was formed in
EOF;
$str = preg_replace('/^\*([^\*].*)$/', '<h1>$1</h1>', $str);
echo $str;
//Expected output
<h1>Portfolio</h1>
Our work includes...
<h1>Company Profile</h1>
Acme was formed in
//Current output either works if there's only one line.
</div>