Solved

Show first few LI from UL html code?

Posted on 2006-10-31
7
209 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
  • 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
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

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…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now