Solved

Show first few LI from UL html code?

Posted on 2006-10-31
7
220 Views
Last Modified: 2013-12-24
I am pulling html code from a database.
The code is inserted with a rich text editor on a text area,
and the client is formatting the text as a list of bullet points.

I want to show the first few <li> from the list,
and then insert a closing <ul>.

How can I grab just the beginning section from the example below,
cutting off just after the third closing </li>

===================================

<ul>  
<li>Three Bedroom Two Bath </li>  
<li>1772&nbsp; Square feet </li>  
<li>Two Car Garage </li>
<li>Covered Patio &nbsp; </li>
<li>Jetted Tube and Separate Shower in Master </li>
<li>Tile Surrounds in Bathroom </li>
<li>Tile Entry Way </li>
<li>10 feet Coffered Ceilings </li>
<li>Front and Rear Landscaped </li>
</ul>

=============  I want to get/show this ============

<ul>  
<li>Three Bedroom Two Bath </li>  
<li>1772&nbsp; Square feet </li>  
<li>Two Car Garage </li>

==========================

Thanks in advance!



0
Comment
Question by:MichaelEvangelista
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Expert Comment

by:Marco_van_den_Oever
ID: 17844028
If this code is pulled from a database from without one field you can't use repeat regions that you can program to show 1 or 5 rows of <li></li> tags, so that's your problem right now i think ? ok:

1. you could change the method of storing these html code so that you insert one row: <li>Two Car Garage </li>  at a time so that you can use a repeat region that you will repeat between the <ul>  and </ul> tags, then you can program to show 1 or 5 of these rows

2. you could use something as #left(table.field,100)#, so that you just pull the first 100 characters, the problem then is that you have to be sure about the length of the <li></li> rules, otherwise maybe you will mis a closing </li> because that was on position 106 while your characters show up till 100...

I think 1 is the best solution...

Is this something you can work with? I can be more specific if you need?

Let me know!:)
0
 

Author Comment

by:MichaelEvangelista
ID: 17844079
Hi Marco.
It is all one field, with the code as shown above, and maybe even a few <p>whatever</p> in there too, depending how client uses the wysiwyg.

I dont want to use #left(whatever)# because the length is variable.

I need to use some type of code to find the third time the string </li> appears in the data, and drop everything after that.
0
 
LVL 15

Accepted Solution

by:
danrosenthal earned 250 total points
ID: 17844689
Select the field from the database and have CF trim the variable:

<CFSET listitems = 3>
<CFSET s = 0>
<CFLOOP from="1" to="#listitems#" index="i">
      <CFSET s = refindnocase("</li>",mystring,s+1)>
</cfloop>
<CFSET mystring = LEFT(mystring,s+4)>
0
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 
LVL 2

Expert Comment

by:Marco_van_den_Oever
ID: 17844747
Nice one:)

<cfquery name="test" datasource="test">
SELECT html
FROM db</cfquery>

<CFSET listitems = 3>
<CFSET s = 0>
<CFLOOP from="1" to="#listitems#" index="i">
     <CFSET s = refindnocase("</li>",#test.html#,s+1)>
</cfloop>
<CFSET mystring = LEFT(#test.html#,s+4)>

<cfoutput>
#mystring#
</cfoutput>

This works great for me, all credits ofcourse to danrosenthal :)
0
 

Author Comment

by:MichaelEvangelista
ID: 17845246
Well done Dan - thanks so much!

Here is the page...
http://www.sshomes.info/specials.cfm

Here is my code...

( decided to go for 4 since you made it so easy!)


<CFSET listitems = 4>
<CFSET s = 0>
<CFLOOP from="1" to="#listitems#" index="i">
     <CFSET s = refindnocase("</li>",recordMainText,s+1)>
</cfloop>
<CFSET recordTextSnip = LEFT(recordMainText,s+4)>


<cfoutput>#recordTextSnip#</cfoutput>


====== thanks again ======
0
 
LVL 15

Expert Comment

by:danrosenthal
ID: 17845499
No problem. Nice looking site!
-Dan
0
 

Author Comment

by:MichaelEvangelista
ID: 17845563
Thanks Dan - the content is being entered through a combination of
my little CF CMS system (with a mySQL database) and straight-up html layout.
Your little bit of code was the icing on the cake for that 'listings' page, which is all being entered and maintained by the client.
0

Featured Post

Plug and play, no additional software required!

The ATEN UE3310 USB3.1 Gen1 Extender Cable allows users to extend the distance between the computer and USB devices up to 10 m (33 ft). The UE3310 is a high-quality, cost-effective solution for professional environments such as hospitals, factories and business facilities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question