ツ.jp
ツ.jp

Reputation: 315

Handle string in PHP, ignoring HTML tags

I am trying to handle a string, of possible input

'something <p>hi</p> <br />'

The input string could contain any, or no HTML tags. I want to handle this string without formatting it.

Essentially I am splitting it at the moment, with a delimiter of &, and I need the output array produced to still contain the input

etc....

$ajaxinput = "function=submit&content=this is some page stuff <p>hi</p>";

        echo 'Input : ' . $ajaxinput . '<br /><br /><br />';

        $output = explode("&", $ajaxinput);
        echo 'Split : ' . $output[0] . '<br /><br />';
        echo 'Split : ' . $output[1];

Output is:

Input : function=submit&content=this is some page stuff
hi




Split : function=submit

Split : content=this is some page stuff
hi

I want:

Input : function=submit&content=this is some page stuff <p>hi</p>




Split : function=submit

Split : content=this is some page stuff <p>hi</p>

Upvotes: 0

Views: 1177

Answers (2)

user399666
user399666

Reputation: 19879

Have a look into htmlentities if you want to display those tags (that's my assumption after reading your question):

echo htmlentities($str, ENT_QUOTES, "UTF-8");

htmlentities will convert all applicable characters to HTML entities.

Upvotes: 0

&#193;lvaro Gonz&#225;lez
&#193;lvaro Gonz&#225;lez

Reputation: 146450

Since you don't remove the HTML tags, they must be there. But since they are HTML tags, you can't see them in the browser unless you use the "View source" menu item.

Upvotes: 1

Related Questions