<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Tagliare un articolo]]></title><description><![CDATA[<p dir="auto">Salve ragazzi ho un problema, anzi l'ho sempre avuto, vorrei poter tagliare un testo lungo di un articolo in modo che possa mostrare un anteprima,<br />
ora, il problema non e tanto tagliare il testo in sè, senza troncare le parole, a questo ho i l rimedio, ma vorrei che non lasciasse tags nel testo aperti, che sò uno &lt;strong&gt; o un &gt;em&gt; ecc ecc, potrei usare uno strip_tags(), ma vorrei che tenesse gli accapo, eventuali immagini ad inizio articolo ecc,</p>
<p dir="auto">conoscete un metodo valido?</p>
]]></description><link>https://dev.connect.gt/topic/162012/tagliare-un-articolo</link><generator>RSS for Node</generator><lastBuildDate>Wed, 25 Nov 2026 23:37:11 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/162012.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 28 Nov 2011 20:43:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Tagliare un articolo on Tue, 29 Nov 2011 13:22:59 GMT]]></title><description><![CDATA[<p dir="auto">perfetto, grazie <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=12b9555a9a1" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:1.4em;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
]]></description><link>https://dev.connect.gt/post/1038940</link><guid isPermaLink="true">https://dev.connect.gt/post/1038940</guid><dc:creator><![CDATA[khendall]]></dc:creator><pubDate>Tue, 29 Nov 2011 13:22:59 GMT</pubDate></item><item><title><![CDATA[Reply to Tagliare un articolo on Tue, 29 Nov 2011 10:26:33 GMT]]></title><description><![CDATA[<p dir="auto">Ciao Khendall,<br />
puoi usare questa classe:</p>
<pre><code class="language-php">class String {
	public static function truncate($text, $length, $suffix = '&amp;hellip;', $isHTML = true){
		$i = 0;
		$tags = array();
		if($isHTML){
			preg_match_all('/&lt;[^&gt;]+&gt;([^&lt;]*)/', $text, $m, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
			foreach($m as $o){
				if($o[0][1] - $i &gt;= $length)
					break;
				$t = substr(strtok($o[0][0], " \t\n\r\0\x0B&gt;"), 1);
				if($t[0] != '/')
					$tags[] = $t;
				elseif(end($tags) == substr($t, 1))
					array_pop($tags);
				$i += $o[1][1] - $o[0][1];
			}
		}
		
		$output = substr($text, 0, $length = min(strlen($text),  $length + $i)) . (count($tags = array_reverse($tags)) ? '&lt;/' . implode('&gt;&lt;/', $tags) . '&gt;' : '');
		
		// Get everything until last space
		$one = substr($output, 0, strrpos($output, " "));
		// Get the rest
		$two = substr($output, strrpos($output, " "), (strlen($output) - strrpos($output, " ")));
		// Extract all tags from the last bit
		preg_match_all('/&lt;(.*?)&gt;/s', $two, $tags);
		// Add suffix if needed
		if (strlen($text) &gt; $length) { $one .= $suffix; }
		// Re-attach tags
		$output = $one . implode($tags[0]);
		
		return $output;
	}
}
</code></pre>
]]></description><link>https://dev.connect.gt/post/1038939</link><guid isPermaLink="true">https://dev.connect.gt/post/1038939</guid><dc:creator><![CDATA[thedarkita]]></dc:creator><pubDate>Tue, 29 Nov 2011 10:26:33 GMT</pubDate></item></channel></rss>