Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Show first few LI from UL html code?

Posted on 2006-10-31
7
Medium Priority
?
225 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 1000 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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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 …
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

916 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