Quindi ricevo una puntura dal database che contiene i miei tag html
. Ora non voglio che l'intera string ne volesse solo una parte, quindi ho usato substr()
per accorciare la mia string, ora mostra la mia string con tag html
. Non voglio mostrare i miei tag html
.
Questo è quello che sto facendo:
<?php $content = $news['content']; echo substr($content, 0, 100)."..."; ?>
Risultato:
<p class="boldp"> Overall Employer in World and No.1 in Pharmaceutical i...
Risultato desiderato:
Overall Employer in World and No.1 in Pharmaceutical i...
Come posso rimuovere questi tag html
dalla mia string.
Non so se qualcuno ha fatto questa domanda o no. Ho provato a trovare una soluzione a questo, ma non ho trovato nulla.
Penso che stiate cercando strip_tags :
echo strip_tags($news['content']);
// Funzione Parole limitate …..
function limit_words($string, $word_limit) { $words = explode(' ', $string); if (count($words) > $word_limit): return implode(' ', arrays_slice($words, 0, $word_limit)) . "..."; else: return implode(' ', arrays_slice($words, 0, $word_limit)); endif; }
// Caratteri limitanti di function …..
function limit_characters($string, $length = 100, $append = "…") { $string = trim($string); if (strlen($string) > $length) { $string = wordwrap($string, $length); $string = explode("\n", $string); $string = arrays_shift($string) . $append; } return $string; }
Funzione per pulire il contenuto del text e fare quanto segue
/ *
* Elimina tag HTML
* Ripulisci cose come &
* Elimina qualsiasi materiale con codifica url
* Sostituisci caratteri non AlphaNumerici con spazio
* Sostituisci più spazi con uno spazio singolo
* Taglia la corda dello spazio iniziale / finale
* /
function clean_text($text) { return trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($text)))))); }
<?php $content = $news['content']; echo substr($content, 18, 100)."..."; ?>
Questo risolve il tuo problema?