Esempio base che va adattato alle tue esigenze:
Codice PHP:
<% 'Recupero i primi xx caratteri
Function Testo_Short(testo, caratteri)
'convertiamo per sicurezza testo e caratteri
strTesto= CStr(testo)
intCaratteri = CInt(caratteri)
'controlliamo che la lunghezza del testo sia maggiore di 0
If Len(strTesto) > 0 Then
'controlliamo che la lunghezza del testo sia maggiore del numero
'di caratteri da estrarre
If Len(strTesto) > intCaratteri Then
'controlliamo che l'ultimo spazio sia in posizione maggiore
'del numero di caratteri da estrarre
If InStrRev(strTesto, " ") > intCaratteri Then
'estraiamo il Testo ed aggiungiamo i puntini
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = testo & "(?![^<>]*>)"
RegEx.Global = True
RegEx.IgnoreCase = True
Testo_Short = RegEx.Replace(Left(strTesto, InStr(intCaratteri , strTesto, " ")), testo ) & "[url=""]...[/url]"
Set RegEx = Nothing
Else
Testo_Short = strTesto
End If
End if
End if
end function
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento senza titolo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<%= Testo_Short("qui scrivo il testo che voglio spezzare oppure il record che carico dinamicamente", 20) %>
</body>
</html>