0

Is it possible to select part of a text from within a DB where the string starts with UL and finish with /UL ?

In the database product description there is a record in a text column with html special characters like this

ul><li>Upper line : 2650/300/720<br></li><li>Down line : 2050/600/900 <br></li><li>Height : 480mm<br></li></ul>

But there is more text and html around this ul:

</span></p><div><span style="font-weight: bold;">Size:</span><br></div><p style="margin-bottom: 20px;"></p><ul><li>Upper line : 2650/300/720<br></li><li>Down line : 2050/600/900 <br></li><li>Height : 480mm<br></li></ul>

Is there any way to select/extract only the part from text that starts and ends with ul ?

ross
  • 2,684
  • 2
  • 13
  • 22

1 Answers1

0

Yes, you can use SUBSTRING_INDEX and SUBSTRING.

But personally, I would prefer extracting the substring in PHP. Example of code using PHP:

function get_substring($string, $start, $end){
    $string = ' ' . $string;
    $ini = strpos($string, $start);
    if ($ini == 0) return '';
    $ini += strlen($start);
    $len = strpos($string, $end, $ini) - $ini;
    return substr($string, $ini, $len);
}
$fullstring = 'Words words words <ul> you are awesome </ul>';
$myString = get_substring($fullstring, '<ul>', '</ul>');

echo $myString;

I would recommend you to check this answer for more code samples: How to get a substring between two strings in PHP?

Maurice
  • 280
  • 3
  • 14