how to remove html tags in php?

前端 未结 6 1761
时光说笑
时光说笑 2020-12-19 15:26

i posted some data using tinymce (in a symfony project).while retrieving back how can i remove html tags? strip_tags not working..

相关标签:
6条回答
  • 2020-12-19 15:41

    When using Symfony, be sure to use the getRaw() function otherwise the text cannot be stripped from it's HTML code, for example:

    $myText = $sf_data->getRaw('myVarContainingText');

    Then use strip_tags() as such:

    $myText = strip_tags( $sf_data->getRaw('myVarContainingText') );

    0 讨论(0)
  • 2020-12-19 15:46

    You could use strip_tags:

    strip_tags('your text or variable');
    

    It should work in symfony. Make sure that you have done everything correctly.

    0 讨论(0)
  • 2020-12-19 15:47

    The easies way is to use strip_tags but it's not very reliable. There is a very, very, VERY good project design specifically for this: HTML Purifier.

    It battle-hardened, tested and very good. strip_tags is the easy, fast and go way, but it can miss out some malformated html that a browser will actually parse and execute.


    Please, don't use regular expression to parse html!

    0 讨论(0)
  • 2020-12-19 15:51

    strip_tags(); you need to put what ever your $ is wrapped with html. ...........

    0 讨论(0)
  • 2020-12-19 15:54

    Try this:

    echo strip_tags($this->getContent(ESC_RAW))
    
    0 讨论(0)
  • 2020-12-19 15:56

    Note that strip_tags returns a new string. It does not modify the original string, i.e:

    $html = '<p>Test</p>';
    strip_tags($html); // Throws away the result, since you don't assign the return 
                       // value of the function to a variable
    
    $stripped = strip_tags($html);
    echo $stripped; // echos 'Test'
    
    0 讨论(0)
提交回复
热议问题