Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
428 views
in Technique[技术] by (71.8m points)

PHP removing html tags from string

I have string:

<p justify;"="">Vers-lo cent-rai Lie-tu-vos ne-kil-no-ja-mo-jo turto pl?t-ros aso-cia-ci-jos kon-kur-se  ...</p>

and want want remove tag

<p justify;"=""></p>

my code:

$content = strip_tags($text, '<p>');

but i get empty string: string(0) "" , what I do wrong ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try to put it like that

$content = strip_tags($text);

Or you can do it with regular expression like that:

$content = preg_replace('/<[^>]*>/', '', $text);

By this $content = strip_tags($text, '<p>'); you are allowing the <p> tag in the string.

For more info see the link http://php.net/manual/en/function.strip-tags.php


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...