在字符串的开头标识HTML标记并将其删除

I want to get html tag in string at starting position and remove it from the string

my demo strings are below:

<I>little willingness</I> that, as the Course itself was to emphasise

this will return <I> tag as o/p

<p>little willingness</p> that, as the Course itself was to emphasise

this will return <p> tag as o/p

little willingness that, <p>as the Course itself was to emphasise</p>

this will return me null as o/p

How do I modify my code below to check only for HTML tags at the start of the line and then remove them?

preg_match("/<[^<]+>/",$string,$m);

First Step:

$paragraph = "<p><i>Please don't</i> blow me to pieces. How to put span here.</p>";
$sentences = explode(".", $paragraph);

Next, add span tags to each sentence:

foreach($sentences as &$sentence) {
    $sentence = "<span>$sentence</span>";
}

Finally, re-implode them into a paragraph:

$paragraph = implode(".", $sentences);

Code

<?php
$str = "<I>little willingness</I> that, <b>as</b> the Course itself was to emphasise again and again.";
if(preg_match('/^(<.*?>)/', $str, $matches))
{
    $str = preg_replace('/^(<.*?>)/', '', $str);
}

print $str;
var_dump($matches);

prints:

little willingness</I> that, <b>as</b> the Course itself was to emphasise again and again.
array(2) {
  [0]=>
  string(3) "<I>"
  [1]=>
  string(3) "<I>"
}

So, you get the string without the tag at the beginning and the tag value in $matches.