Initialy i wanted to create a short description of a text to be shown as preview, I found the following which worked OK -
$length = 35; // The number of words you want
-
$words = explode(' ', $b_keimeno); // Creates an array of words
-
$true_length=count($words); //to see if description smaller than $length
-
$words = array_slice($words, 0, $length);
-
$s_keimeno = implode(' ', $words);
-
if ($true_length>$length)
-
$s_keimeno.="...";
-
Now however the writer start writting with html tags to make bold,links etc. as a result short preview sometimes cuts before clossing a tag or worse inside an opening tag like <a href=... and the next element after this short description appears weird. Any ideas?
2 2439 pbmods 5,821
Recognized Expert Expert
Heya, mikek12004.
One option is to use strip_tags() to remove any HTML from the preview text ( PHP: strip_tags - Manual).
Short of writing your own string parser, though, I am not aware of any good solution for counting words outside of HTML tags (though I am working on one!).
nathj 938
Recognized Expert Contributor
One solution I used on a project recently was a stored procedure. Now please don't all shout at me normally I'm not a fan but this seemed to work a treat. Also I was editing someone else's code and this was simplest.
So what did I do? -
BEGIN
-
DECLARE iStart, iEnd, iLength int;
-
WHILE Locate( '<', Dirty ) > 0 And Locate( '>', Dirty, Locate( '<', Dirty )) > 0 DO
-
BEGIN
-
SET iStart = Locate( '<', Dirty ), iEnd = Locate( '>', Dirty, Locate('<', Dirty ));
-
SET iLength = ( iEnd - iStart) + 1;
-
IF iLength > 0 THEN
-
BEGIN
-
SET Dirty = Insert( Dirty, iStart, iLength, '');
-
END;
-
END IF;
-
END;
-
END WHILE;
-
RETURN Dirty;
-
END
-
I was using a MySQL database. Then in the code (ASP unfortunately) I called the stored procedure on the full text. I have a site with many categorised pages and the category landing page display the first n characters. so it's character based which can leave you cut up in the middle of a word.
Anyway, you may be able to tweak it to be word based. Otherwise the simple strip-tags would work a treat. A function that has no counter-part in ASP, at least not one I could find.
Still thought I'd share my thoughts.
Cheers and Merry Christmas!
nathj
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Eric Lilja |
last post by:
Hello, I have a text file that contains a number of entries describing a
recipe. Each entry consists of a number of strings. Here's an example file
with only one entry (recipe):
Name=Maple Quill
Process=Interim
Level=10
Technique=Fletching
Knowledge=Woodworking
Device=Sawhorse
Primary components=Refined Maple
|
by: Orloff |
last post by:
Hi,
on most (all?) browsers, when you put the pointer on a
<a href="..." title="popup text">this is a link</a>
without clicking on the link, there is a popup caption with the "popup
text".
I would like to achieve the same with some text that is not a link.
I realized that I could simply make it
<a title="popup text">this is just some text</a>
|
by: Barbara Lindsey |
last post by:
Thank you for your help on the trigger question. The RULE worked for most
of the cases I had for this, but I have one that is giving me trouble.
Here are my table definitions:
CREATE SEQUENCE "stat_id_seq" cache 1;
CREATE TABLE "ref_status" (
"status_id" integer DEFAULT nextval('stat_id_seq') PRIMARY KEY,
"short_name" varchar(5),
"description" varchar(25),
"modified" timestamp with time zone DEFAULT current_timestamp,
|
by: Dixie |
last post by:
I wish to add some fields to an existing table in code.
I am using the following code from rkc.
CurrentDb.Execute ("ALTER TABLE MyTable ADD MyNewField Text 25")
This works , but I need to also set the Required, Allow Zero Length and
Indexed attributes. I have tried but keep getting a syntax error.
Also, can I set the default value of a field in code?
Has anyone some examples of these.
TIA
|
by: snicks |
last post by:
I'm trying to exec a program external to my ASP.NET app using the following
code. The external app is a VB.NET application.
Dim sPPTOut As String
sPPTOut = MDEPDirStr + sID + ".ppt"
Dim p As New System.Diagnostics.Process
'p.Start(MDEPDirStr & "macrun.exe", sPPTOut)
p.Start("C:\WINDOWS\SYSTEM32\CALC.EXE")
'p.Start("C:\WINDOWS\SYSTEM32\macrun.exe", sPPTOut)
| |
by: Xh |
last post by:
Hi all,
I have successfully installed DB2 Net Search Extender.
DB2Ext is up and running, I've run successfully this command:
db2text ENABLE DATABASE FOR TEXT CONNECT TO TEST1;
but when I try to execute this statement:
|
by: DavidPr |
last post by:
I'm creating (trying to create) a picture gallery for my website.
The script is not working. I've been working on it now for about 80 hours with no success. My php skills aren't very good.
This picture gallery uses 2 mysql tables: acwrtcats and acwrtpics
The table acwrtcats has 2 fields: cat_name and cat_desc. The cat_name is the name of a category that pictures will be filed under, and cat_desc is a brief description of the category.
...
|
by: GloStix |
last post by:
Okay, when I click the link it dissapears and makes a white space underneath it but the space is clickable. so when you click the space, the link actually works
Used Firefox 3.0 RC2 for this.
OS X 10.5
http://www.screencast.com/t/wgztYUrdN (Video)
http://www.jameswmann.com/music.htm (The actual page)
HTML
|
by: mlthomas007 |
last post by:
Hi,
A client asked for a code book (all fields, descriptions, tables, etc.) from
our Access database. Has anyone had to do this? It seems to me there must
be a way to extract all this information from Access.
Any assistance would be wonderful.
Thanks.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |