Jump to content

Removing text between <LI> tags


jwhite68

Recommended Posts

Can anyone recommend how I can remove any text that lies between the <LI> tags. eg if its :

 

<LI class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; COLOR: black; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto">

 

I want to strip out everything to leave only <LI>.  I assume something like preg_replace, but can anyone advise how?

Link to comment
Share on other sites

<pre>
<?php
$str = '<UL><LI class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; COLOR: black; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto">Text</LI></UL>';
echo preg_replace('/<(li)[^>]*>/i', '<\1>', $str);
?>
</pre>

Link to comment
Share on other sites

The source text I have (from a client) seems to miss the end </LI> tags. Heres part of it.  I tried your code, but it doesnt strip the other tags within the LI tag:

 

<UL type=disc>
<LI class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; COLOR: black; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 8.5pt">1x 1 Sudio apartment</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 8.5pt"><o:p></o:p></SPAN> 
<LI class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; COLOR: black; tab-stops: list 36.0pt; mso-list: l0 level1 lfo1; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto"><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 8.5pt">1</SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-ansi-language: EN-US; mso-bidi-font-size: 8.5pt">2</SPAN><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 8.5pt"> x 2 Double bedroom apartments<o:p></o:p></SPAN></LI></UL> 

 

All I want to keep is the text content within LI tags.  not any of the class, style etc attributes.

Link to comment
Share on other sites

Can you explain to me what the '<\1>' does in one of the arguments. I dont understand the presence of '1'.

 

That is a backreference.

 

I tried your code, but it doesnt strip the other tags within the LI tag:

 

You didn't specify this. To better approach this, are there any attributes that you want to allow and if so, in which tags?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.