Solved

Show first few LI from UL html code?

Posted on 2006-10-31
7
213 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 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