jwhite68 Posted September 28, 2007 Share Posted September 28, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/71056-removing-text-between-tags/ Share on other sites More sharing options...
effigy Posted September 28, 2007 Share Posted September 28, 2007 <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> Quote Link to comment https://forums.phpfreaks.com/topic/71056-removing-text-between-tags/#findComment-357273 Share on other sites More sharing options...
jwhite68 Posted October 1, 2007 Author Share Posted October 1, 2007 Can you explain to me what the '<\1>' does in one of the arguments. I dont understand the presence of '1'. Quote Link to comment https://forums.phpfreaks.com/topic/71056-removing-text-between-tags/#findComment-358907 Share on other sites More sharing options...
jwhite68 Posted October 1, 2007 Author Share Posted October 1, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/71056-removing-text-between-tags/#findComment-358911 Share on other sites More sharing options...
effigy Posted October 1, 2007 Share Posted October 1, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/71056-removing-text-between-tags/#findComment-359140 Share on other sites More sharing options...
jwhite68 Posted October 1, 2007 Author Share Posted October 1, 2007 No, I dont want to allow any attributes at all. Sorry that I wasnt clear in my original posting. Quote Link to comment https://forums.phpfreaks.com/topic/71056-removing-text-between-tags/#findComment-359224 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.