Back to PhocacartText class

Method removeFirstTag

public static
removeFirstTag
(mixed $string, mixed $tag = 'p')

Method removeFirstTag - Source code

/*
 * Be aware, tag without any attribute will be removed, used e.g. when editor adds first p tag (without attributes)
 */
public static function removeFirstTag($string, $tag = 'p')
{
    // First
    $needle = '<' . $tag . '>';
    $pos = strpos($string, $needle);
    if ($pos !== false) {
        $string = substr_replace($string, '', $pos, strlen($needle));
    }
    // Last
    $needle = '</' . $tag . '>';
    $pos = strrpos($string, $needle);
    if ($pos !== false) {
        $string = substr_replace($string, '', $pos, strlen($needle));
    }
    return $string;
}